Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	io := NewIo()
	defer io.Flush()
	for {
		n, m := io.NextInt(), io.NextInt()
		if n == 0 {
			break
		}
		dat := make([]Dat, m)
		for i := 0; i < m; i++ {
			dat[i] = Dat{io.NextInt(), io.NextInt(), io.NextInt()}
		}
		sort.Slice(dat, func(i, j int) bool { return dat[i].t < dat[j].t })
		infected := make([]bool, n+1)
		infected[1] = true
		for i := 0; i < m; i++ {
			infected[dat[i].d] = infected[dat[i].d] || infected[dat[i].s]
		}
		cnt := 0
		for i := 0; i <= n; i++ {
			if infected[i] {
				cnt++
			}
		}
		io.Println(cnt)
	}
}

type Dat struct {
	t, s, d int
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := make([]interface{}, 0, len(a))
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := make([]interface{}, 0, len(a))
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}

C++: #include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct data {
    int tm, s, d;
};

bool cmp(const data &a, const data &b)
{
    return a.tm < b.tm;
}

int main()
{
    int N, M;

    while (cin >> N >> M, N || M) {
        vector<data> log(M);
        vector<bool> ic(N);
        int ans = 1;

        ic[0] = true;
        for (int i = 1; i < N; i++)
            ic[i] = false;

        for (int i = 0; i < M; i++) 
            cin >> log[i].tm >> log[i].s >> log[i].d;
        sort(log.begin(), log.end(), cmp);

        for (int i = 0; i < M; i++) 
            if (ic[log[i].s - 1] && !ic[log[i].d - 1]) {
                ic[log[i].d - 1] = true;
                ans++;
            }
        cout << ans << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

typedef pair<int,int>P;
typedef pair<int,P>PP;

int main(){
	int n,m;
	while(cin>>n>>m,n){
		vector<PP>V;
		int t,s,d;
		for(int i=0;i<m;i++){
			cin>>t>>s>>d;
			V.push_back(PP(t,P(s,d)));
		}
		sort(V.begin(),V.end());
		
		int flag[20001]={0};
		flag[1]=1;
		int cnt=1;
		for(int i=0;i<m;i++){
			if(flag[V[i].second.first]==1&&flag[V[i].second.second]==0){
				flag[V[i].second.second]=1;
				cnt++;
			}
		}
		
		cout<<cnt<<endl;
		
	}
	
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define mp(a,b) make_pair((a),(b))
#define eq ==

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> pii;

// →↑←↓
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};


const double EPS = 1e-9;

struct Packet{
    int time,from,to;
    Packet(int time,int from,int to) : time(time),from(from),to(to) {};
};
bool op(Packet left,Packet right){
    return left.time < right.time;
}

int main(){
    while(true){
        int N,M;
        cin >> N >> M;
        if(N == 0 and M == 0) break;
        vector<Packet> packets;
        vector<char> isInfected(N,false);
        isInfected[0] = true;
        for(int i=0;i<M;i++){
            int t,s,d;
            cin >> t >> s >> d;
            s--;d--;
            packets.push_back(Packet(t,s,d));
        }
        sort(all(packets),op);
        for(int i=0;i<M;i++){
            int from = packets[i].from;
            int to = packets[i].to;
            if(isInfected[from]) isInfected[to] = true;
        }
        int cnt = 0;
        for(int i=0;i<N;i++){
            if(isInfected[i]) cnt++;
        }
        cout << cnt << endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	int n,m;
	while(cin>>n>>m){
		if(n==0&&m==0) break;
		int a[m][3],t,s,d;
		for(int i=0;i<m;i++){
			a[i][0]=0;
			a[i][1]=0;
			a[i][2]=0;
		}
		for(int i=0;i<m;i++){
			cin>>t>>s>>d;
			for(int j=i;j>=1;j--){
				if(a[j-1][0]>t){
					a[j][0]=a[j-1][0];
					a[j][1]=a[j-1][1];
					a[j][2]=a[j-1][2];
					goto end;
				}
				else if(a[j-1][0]<=t){
					a[j][0]=t;
					a[j][1]=s;
					a[j][2]=d;
					goto end;
				}
			}
			a[0][0]=t;
			a[0][1]=s;
			a[0][2]=d;
			end:;
		}
		int b[n+1];
		for(int i=2;i<=n;i++){
			b[i]=0;
		}
		b[1]=1;
		int ct=1;
		for(int i=0;i<m;i++){
			if(b[a[i][1]]==1&&b[a[i][2]]==0){
				ct++;
				b[a[i][2]]=1;
			}
		}
		cout<<ct<<endl;
	}
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long

struct edge{ int from, to, cost; };


int n, m;
bool used[20005];

bool comp(const edge& e1, const edge& e2)
{
	return e1.cost < e2.cost;
}

int main()
{
	while (cin >> n >> m, n)
	{
		edge es[20005];
		REP(i, m)
		{
			int a, b, c;
			cin >> a >> b >> c;
			c--; b--;
			es[i] = edge{ b, c, a };
		}
		sort(es, es + m, comp);
		memset(used, false, sizeof(used));
		used[0] = true;
		REP(i, m)
		{
			if (used[es[i].from]) used[es[i].to] = true;
		}
		int cnt = 0;
		REP(i, n)
		{
			if (used[i]) cnt++;
		}
		cout << cnt << endl;
	}
	return 0;
}