Problem:
Problem A:
Infected Computer
Adam Ivan is working as a system administrator at Soy Group, Inc. He is now facing at a big trouble:
a number of computers under his management have been infected by a computer virus. Unfortunately,
anti-virus system in his company failed to detect this virus because it was very new.
Adam has identified the first computer infected by the virus and collected the records of all data packets
sent within his network. He is now trying to identify which computers have been infected. A computer
is infected when receiving any data packet from any infected computer. The computer is not infected, on
the other hand, just by sending data packets to infected computers.
It seems almost impossible for him to list all infected computers by hand, because the size of the packet
records is fairly large. So he asked you for help: write a program that can identify infected computers.
Input
The input consists of multiple datasets. Each dataset has the following format:
N M
t
1
s
1
d
1
t
2
s
2
d
2
...
t
M
s
M
d
M
N
is the number of computers;
M
is the number of data packets;
t
i
(1 ≤
i
≤
M
) is the time when the
i
-th
data packet is sent;
s
i
and
d
i
(1 ≤
i
≤
M
) are the source and destination computers of the
i
-th data packet
respectively. The first infected computer is indicated by the number 1; the other computers are indicated
by unique numbers between 2 and
N
.
The input meets the following constraints: 0 <
N
≤ 20000, 0 ≤
M
≤ 20000, and 0 ≤
t
i
≤ 10
9
for
1 ≤
i
≤
N
; all
t
i
's are different; and the source and destination of each packet are always different.
The last dataset is followed by a line containing two zeros. This line is not a part of any dataset and should not be processed.
Output
For each dataset, print the number of computers infected by the computer virus.
Sample Input
3 2
1 1 2
2 2 3
3 2
2 3 2
1 2 1
0 0
Output for the Sample Input
3
1

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using a2 = array<ll, 2>;
using a3 = array<ll, 3>;

bool chmin(auto& a, const auto& b) { return a > b ? a = b, 1 : 0; }
bool chmax(auto& a, const auto& b) { return a < b ? a = b, 1 : 0; }

ll mod = 998244353;
const ll INF = 1e18;

ifstream in;
ofstream out;

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    if(argc > 2) {
        in.open(argv[1]);
        cin.rdbuf(in.rdbuf());
        out.open(argv[2]);
        cout.rdbuf(out.rdbuf());
    }

    while(1) {
        ll n, m;
        cin >> n >> m;
        if(n == 0) break;

        vector<a3> v(m);
        for(auto& x : v) cin >> x[0] >> x[1] >> x[2];

        sort(v.begin(), v.end());

        vector<ll> ans(n, 0);
        ans[0] = 1;
        for(auto [_, from, to] : v) {
            from--;
            to--;
            ans[to] |= ans[from];
        }
        cout << accumulate(ans.begin(), ans.end(), 0LL) << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 4068
final_rank: 7

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

using ll = long long;

bool chmin(auto &a, auto b) { return a > b ? a = b, true : false; }
bool chmax(auto &a, auto b) { return a < b ? a = b, true : false; }

bool solve() {
    int N, M;
    cin >> N >> M;
    if (N == 0 && M == 0) return false;
    vector<int> T(M), S(M), D(M);
    for (int i = 0; i < M; i++) {
        cin >> T[i] >> S[i] >> D[i];
        S[i]--, D[i]--;
    }
    vector<int> ord(M);
    iota(ord.begin(), ord.end(), 0);
    ranges::sort(ord, {}, [&] (int i) { return T[i]; });
    vector<bool> A(N);
    A[0] = true;
    for (int i : ord) {
        if (A[S[i]]) A[D[i]] = true;
    }
    int ans = 0;
    for (auto e : A) ans += e;
    cout << ans << '\n';
    return true;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    while (solve()) {}
}
accuracy: 1
time_ms: 30
memory_kb: 3968
final_rank: 6

code_snippet: #include<bits/stdc++.h>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>

using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ve = vector<vector<int>>;
using vb = vector<bool>;
using vvb = vector<vb>;
#define rep(i,s,n) for(ll i = (ll)s;i < (ll)n;i++)
#define rrep(i,l,r) for(ll i = r-1;i >= l;i--)
#define ALL(x) (x).begin(),(x).end()
#define sz(c) ((ll)(c).size())
#define LB(A,x) (int)(lower_bound(A.begin(),A.end(),x)-A.begin())
#define UB(A,x) (int)(upper_bound(A.begin(),A.end(),x)-A.begin())
// #define MOD 1000000007
#define MOD 998244353
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<typename T>ostream&operator<<(ostream&os,vector<T>&v){for(int i = 0;i < v.size();i++)os<<v[i]<<(i+1!=v.size()?" ":"");return os;}
template<typename T>istream&operator>>(istream&is,vector<T>&v){for(T&in:v)is>>in;return is;}
template<typename T1,typename T2>ostream&operator<<(ostream&os,pair<T1,T2>&p){os<<p.first<<" "<<p.second;return os;}
template<typename T1,typename T2>istream&operator>>(istream&is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}
template<typename T> inline bool chmax(T &a,T b){if(a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a,T b){if(a > b){a = b;return true;}return false;}
ld dist(ld x1,ld y1,ld x2, ld y2){return sqrtl((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}

class UnionFind{
  public:
  vector<int> par;
  UnionFind(long long size) : par(size,-1){}
  bool unite(int x,int y){
    x = root(x),y = root(y);
    if(x == y)return false;
    if(par[y] < par[x])swap(x,y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }
  bool find(int x,int y){
    return root(x) == root(y);
  }
  int root(int x){
    return par[x] < 0 ? x : par[x] = root(par[x]);
  }
  int size(int x){
    return -par[root(x)];
  }
};


int main(){
  
  ios_base::sync_with_stdio(0), cin.tie(0);
  while(1){
    int n,m;cin >> n >> m;
    if(!n)break;
    vector<tuple<int,int,int>> v(m);
    rep(i,0,m){
      auto &[t,s,d] = v[i];
      cin >> t >> s >> d;s--;d--;
    }
    sort(ALL(v));
    UnionFind uf(n);
    rep(i,0,m){
      auto [t,s,d] = v[i];
      if(uf.find(0,s))uf.unite(s,d);
    }
    cout << uf.size(0) << "\n";
  }
  

  return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 3680
final_rank: 3

code_snippet: #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int N = 20020;
bool tag[N];
struct P{
    int t, s, d;
    void in() {scanf("%d %d %d", &t, &s, &d);}
    bool operator<(const P& a)const {return t < a.t;}
}p[N];

int main()
{
    int n, m, i, j;
    while(~scanf("%d %d", &n, &m), n+m) {
        for(i = 0; i < m; ++i) {
            p[i].in();
        }
        sort(p, p+m);
        memset(tag, 0, sizeof(tag));
        tag[1] = 1;
        for(i = 0; i < m; ++i) {
            int k1 = p[i].s, k2 = p[i].d;
//            printf(".. %d %d   ", k1, k2);
            tag[k2] = (tag[k1] | tag[k2]);
//            printf(".. %d\n", tag[k2]);
        }
        int cnt = 0;
        for(i = 1; i <= n; ++i) if(tag[i]) cnt++;
        printf("%d\n", cnt);
    }
    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 3740
final_rank: 4

code_snippet: #include <iostream>
#include <queue>
#include <string.h>
using namespace std;
struct E{
	long long int t;
	int from,to;
	bool operator<(const E& e1)const{
		return t>e1.t;
	}
};
void f(int n,int m){
	int memo[20003];
	memset(memo,0,sizeof(memo));
	memo[1]=1;
	priority_queue<E> pq;
	for(int i=0;i<m;i++){
		E e1;
		cin>>e1.t>>e1.from>>e1.to;
		pq.push(e1);
	}
	while(pq.size()>0){
		E e1=pq.top();
		pq.pop();
		if(memo[e1.from]==1)memo[e1.to]=1;
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		ans+=memo[i];
	}
	cout<<ans<<endl;
}


int main() {
	int n,m;
	while(true){
		cin>>n>>m;
		if(n+m==0)break;
		f(n,m);
	}
	return 0;
}
accuracy: 1
time_ms: 130
memory_kb: 3848
final_rank: 17

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

struct packet {
	int t, s, d;
	bool operator<(const packet& p) const {
		return t < p.t;
	}
};

int main() {
	while (true) {
		int N, M;
		cin >> N >> M;
		if (N == 0 && M == 0) {
			break;
		}
		vector<packet> P(M);
		for (int i = 0; i < M; i++) {
			cin >> P[i].t >> P[i].s >> P[i].d;
			P[i].s--;
			P[i].d--;
		}
		sort(P.begin(), P.end());
		vector<bool> infected(N, false);
		infected[0] = true;
		for (packet p : P) {
			if (infected[p.s]) {
				infected[p.d] = true;
			}
		}
		int ans = 0;
		for (int i = 0; i < N; i++) {
			ans += int(infected[i]);
		}
		cout << ans << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 130
memory_kb: 3608
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(a) a.begin(),a.end()
#define reps(i, a, n) for (int i = (a); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)
#define rreps(i, a, n) for (int i = (a); i > (int)(n); i--)
const long long mod = 1000000007;
const long long INF = 1e18;
ll myceil(ll a, ll b) {return (a+b-1)/b;}

int n,m;

void solve() {
    vector<vector<int>> v(m,vector<int> (3));
    rep(i,m) {
        rep(j,3) {
            cin >> v[i][j];
        }
    }

    sort(all(v));

    vector<bool> in(n,false);
    in[0] = true;
    int ans = 1;
    rep(i,m) {
        if (in[v[i][1]-1] && !in[v[i][2]-1]) {
            ans++;
            in[v[i][2]-1] = true;
        }
    }

    cout << ans << endl;
    return;

}


int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    while (cin >> n >> m && n != 0) {
        solve();
    }
}
accuracy: 1
time_ms: 60
memory_kb: 4556
final_rank: 16

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

struct my{
    int t, v, u;
};

bool cmp(my &a,my &b){
    return a.t < b.t;
}

int main() {

    int n, m;
   while(cin >> n >> m){
    if(n == 0 && m == 0)break;
    my a[m + 1];
    bool used[n + 1];
    for(int i = 1; i <= m; ++i){
        cin >> a[i].t >> a[i].v >> a[i].u;
    }

    sort(a + 1,a + m + 1, cmp);

    for(int i = 1; i <= n; ++i)used[i] = false;
    used[1] = true;

    for(int i = 1; i <= m; ++i){
        int v = a[i].v;
        int u = a[i].u;
        if(used[v]){
            used[u] = true;
        }
    }
    int ans = 0;

    for(int i = 1; i <= n; ++i){
        ans += (used[i] == true);
    }

    cout << ans << '\n';

   }

    return 0;
}
accuracy: 1
time_ms: 160
memory_kb: 3336
final_rank: 13

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

const int MAX_N = 2e5 + 121;

struct my{
    int t, v, u;
};

my a[MAX_N];

bool cmp(my &a,my &b){
    return a.t < b.t;
}

bool used[MAX_N];

int main() {

    int n, m;
   while(cin >> n >> m){
    if(n == 0 && m == 0)break;
    for(int i = 1; i <= m; ++i){
        cin >> a[i].t >> a[i].v >> a[i].u;
    }

    sort(a + 1,a + m + 1, cmp);

    for(int i = 1; i <= n; ++i)used[i] = false;
    used[1] = true;

    for(int i = 1; i <= m; ++i){
        int v = a[i].v;
        int u = a[i].u;
        if(used[v]){
            used[u] = true;
        }
    }
    int ans = 0;

    for(int i = 1; i <= n; ++i){
        ans += (used[i] == true);
    }

    cout << ans << '\n';

   }

    return 0;
}
accuracy: 1
time_ms: 160
memory_kb: 3364
final_rank: 14

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

#include <unistd.h>

namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf


uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
    char num[10000][4];
    constexpr Pre() : num() {
        for (int i = 0; i < 10000; i++) {
            int n = i;
            for (int j = 3; j >= 0; j--) {
                num[i][j] = n % 10 | '0';
                n /= 10;
            }
        }
    }
} constexpr pre;

inline void load() {
    memmove(ibuf, ibuf + pil, pir - pil);
    pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
    pil = 0;
    if (pir < SZ)
        ibuf[pir++] = '\n';
}

inline void flush() {
    fwrite(obuf, 1, por, stdout);
    por = 0;
}

void rd(char &c) {
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
}

void rd(string &x) {
    x.clear();
    char c;
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
    do {
        x += c;
        if (pil == pir)
            load();
        c = ibuf[pil++];
    } while (!isspace(c));
}

template <typename T> void rd_real(T &x) {
    string s;
    rd(s);
    x = stod(s);
}

template <typename T> void rd_integer(T &x) {
    if (pil + 100 > pir)
        load();
    char c;
    do
        c = ibuf[pil++];
    while (c < '-');
    bool minus = 0;
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (c == '-') {
            minus = 1, c = ibuf[pil++];
        }
    }
    x = 0;
    while ('0' <= c) {
        x = x * 10 + (c & 15), c = ibuf[pil++];
    }
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (minus)
            x = -x;
    }
}

void rd(int &x) {
    rd_integer(x);
}
void rd(ll &x) {
    rd_integer(x);
}
void rd(i128 &x) {
    rd_integer(x);
}
void rd(uint &x) {
    rd_integer(x);
}
void rd(ull &x) {
    rd_integer(x);
}
void rd(u128 &x) {
    rd_integer(x);
}
void rd(double &x) {
    rd_real(x);
}
void rd(long double &x) {
    rd_real(x);
}

template <class T, class U> void rd(pair<T, U> &p) {
    return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T> void rd_tuple(T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
        auto &x = std::get<N>(t);
        rd(x);
        rd_tuple<N + 1>(t);
    }
}
template <class... T> void rd(tuple<T...> &tpl) {
    rd_tuple(tpl);
}

template <size_t N = 0, typename T> void rd(array<T, N> &x) {
    for (auto &d : x)
        rd(d);
}
template <class T> void rd(vector<T> &x) {
    for (auto &d : x)
        rd(d);
}

void read() {}
template <class H, class... T> void read(H &h, T &...t) {
    rd(h), read(t...);
}

void wt(const char c) {
    if (por == SZ)
        flush();
    obuf[por++] = c;
}
void wt(const string s) {
    for (char c : s)
        wt(c);
}
void wt(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++)
        wt(s[i]);
}

template <typename T> void wt_integer(T x) {
    if (por > SZ - 100)
        flush();
    if (x < 0) {
        obuf[por++] = '-', x = -x;
    }
    int outi;
    for (outi = 96; x >= 10000; outi -= 4) {
        memcpy(out + outi, pre.num[x % 10000], 4);
        x /= 10000;
    }
    if (x >= 1000) {
        memcpy(obuf + por, pre.num[x], 4);
        por += 4;
    } else if (x >= 100) {
        memcpy(obuf + por, pre.num[x] + 1, 3);
        por += 3;
    } else if (x >= 10) {
        int q = (x * 103) >> 10;
        obuf[por] = q | '0';
        obuf[por + 1] = (x - q * 10) | '0';
        por += 2;
    } else
        obuf[por++] = x | '0';
    memcpy(obuf + por, out + outi + 4, 96 - outi);
    por += 96 - outi;
}

template <typename T> void wt_real(T x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << double(x);
    string s = oss.str();
    wt(s);
}

void wt(int x) {
    wt_integer(x);
}
void wt(ll x) {
    wt_integer(x);
}
void wt(i128 x) {
    wt_integer(x);
}
void wt(uint x) {
    wt_integer(x);
}
void wt(ull x) {
    wt_integer(x);
}
void wt(u128 x) {
    wt_integer(x);
}
void wt(double x) {
    wt_real(x);
}
void wt(long double x) {
    wt_real(x);
}

template <class T, class U> void wt(const pair<T, U> val) {
    wt(val.first);
    wt(' ');
    wt(val.second);
}
template <size_t N = 0, typename T> void wt_tuple(const T t) {
    if constexpr (N < std::tuple_size<T>::value) {
        if constexpr (N > 0) {
            wt(' ');
        }
        const auto x = std::get<N>(t);
        wt(x);
        wt_tuple<N + 1>(t);
    }
}
template <class... T> void wt(tuple<T...> tpl) {
    wt_tuple(tpl);
}
template <class T, size_t S> void wt(const array<T, S> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}
template <class T> void wt(const vector<T> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}

void print() {
    wt('\n');
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
    wt(head);
    if (sizeof...(Tail))
        wt(' ');
    print(forward<Tail>(tail)...);
}
void __attribute__((destructor)) _d() {
    flush();
}
} // namespace fastio


using fastio::flush;
using fastio::print;
using fastio::read;

inline void first(bool i = true) {
    print(i ? "first" : "second");
}
inline void Alice(bool i = true) {
    print(i ? "Alice" : "Bob");
}
inline void Takahashi(bool i = true) {
    print(i ? "Takahashi" : "Aoki");
}
inline void yes(bool i = true) {
    print(i ? "yes" : "no");
}
inline void Yes(bool i = true) {
    print(i ? "Yes" : "No");
}
inline void No() {
    print("No");
}
inline void YES(bool i = true) {
    print(i ? "YES" : "NO");
}
inline void NO() {
    print("NO");
}
inline void Yay(bool i = true) {
    print(i ? "Yay!" : ":(");
}
inline void Possible(bool i = true) {
    print(i ? "Possible" : "Impossible");
}
inline void POSSIBLE(bool i = true) {
    print(i ? "POSSIBLE" : "IMPOSSIBLE");
}

/**
 * @brief Fast IO
 */

int main() {
while(1) {
    int N, Q;
    cin >> N >> Q;
    if (N == 0 && Q == 0) return 0;
    vector<bool> B(N, false);
    B[0] = true;
    vector<pair<int,pair<int,int>>> V(Q);
    rep(i,0,Q) {
        cin >> V[i].first >> V[i].second.first >> V[i].second.second;
        V[i].second.first--, V[i].second.second--;
    }
    sort(ALL(V));
    rep(i,0,Q) {
        if (B[V[i].second.first]) B[V[i].second.second] = true;
    }
    int COUNT = 0;
    rep(i,0,N) if (B[i]) COUNT++;
    cout << COUNT << endl;
}
}
accuracy: 1
time_ms: 130
memory_kb: 3648
final_rank: 12

code_snippet: #include <bits/stdc++.h>


using namespace std;
//make -f ../makefile SRC=
/*
WA => time of packet has to be taken into account
*/


//------------------------------------------------------------------------------
bool DEBUG = false;
const int INF = 1000000000;

const int MAX_N = 20000;
static bool marked[MAX_N];
//------------------------------------------------------------------------------
struct Packet
{
    int t, v, w;
    bool operator<(const Packet& p1) const
    {
        if (t == p1.t) return v < p1.v;
        return t < p1.t;
    }

    Packet(): t(-1), v(-1), w(-1) {}
    Packet(int ti, int v1, int v2): t(ti), v(v1), w(v2) {}
    void debug() const { printf("t=%d, v=%d, w=%d\n", t, v, w); }
};

typedef vector<Packet> Packets;
//------------------------------------------------------------------------------
int solve(int N, int M, Packets& P)
{
    sort(P.begin(), P.end());
    for (int v=0; v<N; v++) { marked[v] = false; }
    int m = 0;
    while (m < M && P[m].v != 0) m++;
    if (m >= M || P[m].v != 0) return 1; //<----- gotcha

    marked[0] = true;
    for (m; m<M; ++m)
        if (marked[ P[m].v ])
            marked[ P[m].w ] = true;

    int res = 0;
    for (int v=0; v<N; v++)
        if (marked[v])
            res++;
    return res;
}
//------------------------------------------------------------------------------
void test()
{

}

//------------------------------------------------------------------------------
int main()
{
    //test(); return 0;
    //DEBUG = true;
    //--------------------------------------------------------------------------
    int N, M, v, w, c, num;
    int t = 0;
    while (true)
    {
        num = scanf("%d %d ", &N, &M);
        if (DEBUG && t == 26) printf("%d %d\n", N, M);
        if (N == 0 && M == 0) break;

        Packets P(M);
        for (int m=0; m<M; ++m)
        {
            num = scanf("%d %d %d ", &c, &v, &w);
            if (DEBUG && t == 26) printf("%d %d %d\n", c, v, w);
            v--;
            w--;
            P[m] = Packet(c, v, w);
        }
        int res = solve(N, M, P);
        printf("%d\n", res);
        t++;
    }
    //--------------------------------------------------------------------------
    return 0;
}
//------------------------------------------------------------------------------
accuracy: 1
time_ms: 50
memory_kb: 3724
final_rank: 5

code_snippet: #include <bits/stdc++.h>

bool solve() {
    int n, m; std::cin >> n >> m;
    if (n == 0 and m == 0) return false;
    std::vector<std::tuple<int, int, int>> info(m);
    for (auto& [t, s, d] : info) {
        std::cin >> t >> s >> d;
        s--; d--;
    }
    std::sort(info.begin(), info.end());
    std::vector<bool> a(n);
    a[0] = true;
    for (auto [t, s, d] : info) {
        if (a[s]) a[d] = true;
    } 
    int ans{(int)std::count(a.begin(), a.end(), true)};
    std::cout << ans << '\n';
    return true;
}


int main() {
    std::cin.tie(nullptr)->sync_with_stdio(false);
    for (int i{} ; solve() ; i++) {
    }
}
accuracy: 1
time_ms: 40
memory_kb: 3544
final_rank: 1

code_snippet: #include <bits/stdc++.h>

int solve() {
    int n, m;
    std::cin >> n >> m;
    if (n == 0) return 1;
    std::vector<bool> virus(n);
    virus[0] = true;

    std::vector<std::tuple<int, int, int>> edges;
    for (int i = 0; i < m; i++) {
        int t, u, v;
        std::cin >> t >> u >> v;
        u--; v--;
        edges.emplace_back(t, u, v);
    }
    std::sort(edges.begin(), edges.end());
    for (auto [t, u, v]: edges) {
        if (virus[u]) {
            virus[v] = true;
        }
    }

    std::cout << std::accumulate(virus.begin(), virus.end(), 0) << std::endl;
    return 0;
}

int main() {
    while (!solve());
}
accuracy: 1
time_ms: 130
memory_kb: 3632
final_rank: 11

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> Pi;
int main(){
    int n, m, s[20002], d[20002], t;
    while(cin >> n >> m, n){
        vector<Pi> vec;
        bool vir[20002]={};
        int ans = 1;
        vir[1] = true;
        for(int i=0;i<m;i++){
            cin >> t >> s[i] >> d[i];
            vec.push_back(Pi(t, i));
        }
        sort(vec.begin(), vec.end());
        for(int i=0;i<vec.size();i++){
            if(vir[s[vec[i].second]] && !vir[d[vec[i].second]]) ans++;
            vir[d[vec[i].second]] |= vir[s[vec[i].second]];
        }
        cout << ans << endl;
    }
    return(0);
}
accuracy: 1
time_ms: 160
memory_kb: 3424
final_rank: 15

code_snippet: #include<bits/stdc++.h>
using namespace std;
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

bool solve(){
    int N,M;
    cin>>N>>M;
    if(N==0&&M==0)return false;
    vector<tuple<int,int,int>>vt;
    while(M--){
        int t,s,d;
        cin>>t>>s>>d;
        s--;
        d--;
        vt.push_back(make_tuple(t,s,d));
    }
    sort(vt.begin(),vt.end());
    vector<bool>infected(N);
    infected[0]=true;
    for(auto[t,s,d]:vt){
        if(infected[s])infected[d]=true;
    }
    int ans=0;
    for(int i=0;i<N;i++){
        if(infected[i])ans++;
    }
    cout<<ans<<"\n";
    return true;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    while(1){
        if(!solve()){
            return 0;
        }
    }
}
accuracy: 1
time_ms: 40
memory_kb: 3624
final_rank: 2

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

struct tup{
    int t, s, d;
    tup(int t, int s, int d): t(t), s(s), d(d) {}
};

int main(){
    while(true){
        int n, m; cin >> n >> m;
        if(n == 0) break;
        vector<tup> record;
        for(int i = 0; i < m; i++){
            int t, s, d; cin >> t >> s >> d;
            s--; d--;
            record.emplace_back(t, s, d);
        }
        sort(record.begin(), record.end(), [](const tup &a, const tup &b){
            return a.t < b.t;
        });
        vector<bool> infected(n, false);
        infected[0] = true;
        for(auto &it: record){
            if(infected[it.s]) infected[it.d] = true;
        }
        int ans = 0;
        for(int i = 0; i < n; i++){
            if(infected[i]) ans++;
        }
        cout << ans << '\n';
    }
    return 0;
}
accuracy: 1
time_ms: 130
memory_kb: 3496
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i,end) for(int i = 0; i <= (int)(end); i++)
#define reps(i,start,end) for(int i = start; i < (int)(end); i++)
#define repsn(i,start,end) for(int i = start; i <= (int)(end); i++)
#define ll long long
#define print(t) cout << t << endl 
#define all(a)  (a).begin(),(a).end()
// << std::fixed << std::setprecision(0)
const ll INF = 1LL << 60;
 
template<class T> void chmin(T& a, T b){
 if(a > b){
  a = b;
 }
}
 
template<class T> void chmax(T& a, T b){
 if(a < b){
  a = b;
 }
}
// for AOJ or ICPC or etc..
template<class Tp>
bool zero (const Tp &x) {
    return x == 0;
}

template<class Tp, class... Args>
bool zero (const Tp &x, const Args& ...args) {
    return zero(x) and zero(args...);
}

int main(){
  while(1){
    ll n,m;cin >> n >> m;
    if(zero(n,m))break;
    set<ll> se;
    se.insert(1);
    vector<tuple<ll,ll,ll>> tsd(m);
    rep(i,m){
      ll t,s,d;cin >> t >> s>> d;
      tsd[i] = {t,s,d};
    }
    sort(all(tsd));
    rep(i,m){
      auto [t,s,d] = tsd[i];
      if(se.count(s)){
        se.insert(d);
      }
    }
    cout << se.size() << endl;
  }
}
accuracy: 1
time_ms: 160
memory_kb: 4612
final_rank: 18

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(void){
    ll n,m;
    while(cin>>n>>m,n){
        vector<pair<ll,pair<ll,ll>>> v;
        pair<ll,pair<ll,ll>> p;
        ll a[200010]={0},t,s=0;
        a[1]=1;
        for(ll i=0;i<m;i++){
            cin>>p.first>>p.second.first>>p.second.second;
            v.push_back(p);
        }
        sort(v.begin(),v.end());
        for(ll i=0;i<m;i++){
            if(a[v[i].second.first]){
                a[v[i].second.second]=1;
            }
        }
        for(ll i=0;i<n+1;i++){
            if(a[i]){
                s++;
            }
        }
        cout<<s<<endl;
    }
    return 0;
}
accuracy: 1
time_ms: 130
memory_kb: 5880
final_rank: 20

code_snippet: #line 2 "library/KowerKoint/base.hpp"

#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#endif

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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(ll i = a; i < (ll)(b); i++)
#define ALL(a) (a).begin(),(a).end()
#define END(...) { print(__VA_ARGS__); return; }

using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
using ll = long long;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
using VD = vector<double>;
using VVD = vector<VD>;
using VVVD = vector<VVD>;
using VS = vector<string>;
using VVS = vector<VS>;
using VVVS = vector<VVS>;
using VC = vector<char>;
using VVC = vector<VC>;
using VVVC = vector<VVC>;
using P = pair<int, int>;
using VP = vector<P>;
using VVP = vector<VP>;
using VVVP = vector<VVP>;
using LP = pair<ll, ll>;
using VLP = vector<LP>;
using VVLP = vector<VLP>;
using VVVLP = vector<VVLP>;

template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

constexpr int INF = 1001001001;
constexpr ll LINF = 1001001001001001001ll;
constexpr int DX[] = {1, 0, -1, 0};
constexpr int DY[] = {0, 1, 0, -1};

void print() { cout << '\n'; }
template<typename T>
void print(const T &t) { cout << t << '\n'; }
template<typename Head, typename... Tail>
void print(const Head &head, const Tail &... tail) {
    cout << head << ' ';
    print(tail...);
}

#ifdef ONLINE_JUDGE
template<typename... Args>
void dbg(const Args &... args) {}
#else
void dbg() { cerr << '\n'; }
template<typename T>
void dbg(const T &t) { cerr << t << '\n'; }
template<typename Head, typename... Tail>
void dbg(const Head &head, const Tail &... tail) {
    cerr << head << ' ';
    dbg(tail...);
}
#endif

template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
    os << p.first << " " << p.second;
    return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
    is >> p.first >> p.second;
    return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
    for(int i = 0; i < (int) v.size(); i++) {
        os << v[i] << (i + 1 != (int) v.size() ? " " : "");
    }
    return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
    for(T &in : v) is >> in;
    return is;
}

template<typename T>
vector<vector<T>> split(typename vector<T>::const_iterator begin, typename vector<T>::const_iterator end, T val) {
    vector<vector<T>> res;
    vector<T> cur;
    for(auto it = begin; it != end; it++) {
        if(*it == val) {
            res.push_back(cur);
            cur.clear();
        } else cur.push_back(val);
    }
    res.push_back(cur);
    return res;
}

vector<string> split(typename string::const_iterator begin, typename string::const_iterator end, char val) {
    vector<string> res;
    string cur = "";
    for(auto it = begin; it != end; it++) {
        if(*it == val) {
            res.push_back(cur);
            cur.clear();
        } else cur.push_back(val);
    }
    res.push_back(cur);
    return res;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template <typename T>
pair<VI, vector<T>> compress(const vector<T> &a) {
    int n = a.size();
    vector<T> x;
    REP(i, n) x.push_back(a[i]);
    sort(ALL(x)); x.erase(unique(ALL(x)), x.end());
    VI res(n);
    REP(i, n) res[i] = lower_bound(ALL(x), a[i]) - x.begin();
    return make_pair(res, x);
}

template <typename T>
pair<vector<T>, vector<T>> factorial(int n) {
    vector<T> res(n+1), rev(n+1);
    res[0] = 1;
    REP(i, n) res[i+1] = res[i] * (i+1);
    rev[n] = 1 / res[n];
    for(int i = n; i > 0; i--) {
        rev[i-1] = rev[i] * i;
    }
    return make_pair(res, rev);
}
#line 3 "library/KowerKoint/internal_operator.hpp"

namespace internal_operator {
    template <typename T>
    T default_add(T a, T b) { return a + b; }
    template <typename T>
    T default_sub(T a, T b) { return a - b; }
    template <typename T>
    T zero() { return T(0); }
    template <typename T>
    T default_div(T a, T b) { return a / b; }
    template <typename T>
    T default_mult(T a, T b) { return a * b; }
    template <typename T>
    T one() { return T(1); }
    template <typename T>
    T default_xor(T a, T b) { return a ^ b; }
    template <typename T>
    T default_and(T a, T b) { return a & b; }
    template <typename T>
    T default_or(T a, T b) { return a | b; }
    ll mod3() { return 998244353LL; }
    ll mod7() { return 1000000007LL; }
    ll mod9() { return 1000000009LL; }
}

#line 3 "library/KowerKoint/integer.hpp"

VL divisor(ll n) {
    assert(n > 0);
    VL fow, bck;
    for(ll i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            fow.push_back(i);
            if(i * i != n) bck.push_back(n / i);
        }
    }
    reverse(ALL(bck));
    fow.insert(fow.end(), ALL(bck));
    return fow;
}

bool is_prime(ll n) {
    assert(n > 0);
    for(ll d = 2; d*d <= n; d++) {
        if(n % d == 0) return false;
    }
    return true;
}

VL least_prime_factors(ll n) {
    assert(n > 0);
    VL lpfs(n+1, -1), primes;
    FOR(d, 2, n+1) {
        if(lpfs[d] == -1) {
            lpfs[d] = d;
            primes.push_back(d);
        }
        for(ll p : primes) {
            if(p * d > n || p > lpfs[d]) break;
            lpfs[p*d] = p;
        }
    }
    return lpfs;
}

VL prime_list(ll n) {
    assert(n > 0);
    VL primes;
    vector<bool> sieved(n+1);
    FOR(d, 2, n+1) {
        if(!sieved[d]) {
            primes.push_back(d);
            for(ll i = d*d; i <= n; i += d) sieved[i] = 1;
        }
    }
    return primes;
}

map<ll, int> prime_factor(ll n) {
    assert(n > 0);
    map<ll, int> factor;
    for(ll d = 2; d*d <= n; d++) {
        while(n%d == 0) {
            n /= d;
            factor[d]++;
        }
    }
    if(n > 1) factor[n]++;
    return factor;
}

ll extgcd(ll a, ll b, ll& x, ll& y) {
    x = 1, y = 0;
    ll nx = 0, ny = 1;
    while(b) {
        ll q = a / b;
        tie(a, b) = LP(b, a % b);
        tie(x, nx) = LP(nx, x - nx*q);
        tie(y, ny) = LP(ny, y - ny*q);
    }
    return a;
}

ll inv_mod(ll n, ll m) {
    ll x, y;
    assert(extgcd(n, m, x, y) == 1);
    x %= m;
    if(x < 0) x += m;
    return x;
}

ll pow_mod(ll a, ll n, ll m) {
    if(n == 0) return 1LL;
    if(n < 0) return inv_mod(pow_mod(a, -n, m), m);
    ll res = 1;
    while(n) {
        if(n & 1) {
            res *= a;
            res %= m;
        }
        n >>= 1;
        a *= a;
        a %= m;
    }
    return res;
}

#line 5 "library/KowerKoint/modint.hpp"

template <ll (*mod)()>
struct Modint {
    ll val;
    
    Modint(): val(0) {}

    Modint(ll x): val(x) {
        val %= mod();
        if(val < 0) val += mod();
    }

    Modint& operator+=(const Modint& r) {
        val += r.val;
        if(val >= mod()) val -= mod();
        return *this;
    }
    friend Modint operator+(const Modint& l, const Modint& r) {
        return Modint(l) += r;
    }

    Modint& operator-=(const Modint& r) {
        val -= r.val;
        if(val < 0) val += mod();
        return *this;
    }
    friend Modint operator-(const Modint& l, const Modint& r) {
        return Modint(l) -= r;
    }

    Modint& operator*=(const Modint& r) {
        val *= r.val;
        val %= mod();
        return *this;
    }
    Modint operator*(const Modint& r) {
        return (Modint(*this) *= r);
    }
    friend Modint operator*(const Modint& l, const Modint& r) {
        return Modint(l) *= r;
    }

    Modint pow(ll n) const {
        return Modint(pow_mod(val, n, mod()));
    }

    Modint inv() const {
        return Modint(inv_mod(val, mod()));
    }

    Modint& operator/=(const Modint& r) {
        return (*this *= r.inv());
    }
    friend Modint operator/(const Modint& l, const Modint& r) {
        return Modint(l) /= r;
    }

    Modint& operator^=(const ll n) {
        val = pow_mod(val, n, mod());
        return *this;
    }
    Modint operator^(const ll n) {
        return this->pow(n);
    }

    Modint operator+() const { return *this; }
    Modint operator-() const { return Modint() - *this; }

    Modint& operator++() {
        val++;
        if(val == mod()) val = 0LL;
        return *this;
    }
    Modint& operator++(int) {
        Modint res(*this);
        ++*this;
        return res;
    }

    Modint& operator--() {
        if(val == 0LL) val = mod();
        val--;
        return *this;
    }
    Modint& operator--(int) {
        Modint res(*this);
        --*this;
        return res;
    }

    friend bool operator==(const Modint& l, const Modint& r) {
        return l.val == r.val;
    }
    friend bool operator!=(const Modint& l, const Modint& r) {
        return l.val != r.val;
    }

    static pair<vector<Modint>, vector<Modint>> factorial(int n) {
        vector<Modint> fact(n+1), rfact(n+1);
        fact[0] = 1;
        REP(i, n) fact[i+1] = fact[i] * (i+1);
        rfact[n] = 1 / fact[n];
        for(int i = n-1; i >= 0; i--) rfact[i] = rfact[i+1] * (i+1);
        return {fact, rfact};
    }

    friend istream& operator>>(istream& is, Modint& mi) {
        is >> mi.val;
        return is;
    }

    friend ostream& operator<<(ostream& os, const Modint& mi) {
        os << mi.val;
        return os;
    }
};

using MI3 = Modint<internal_operator::mod3>;
using V3 = vector<MI3>;
using VV3 = vector<V3>;
using VVV3 = vector<VV3>;
using MI7 = Modint<internal_operator::mod7>;
using V7 = vector<MI7>;
using VV7 = vector<V7>;
using VVV7 = vector<VV7>;
using MI9 = Modint<internal_operator::mod9>;
using V9 = vector<MI9>;
using VV9 = vector<V9>;
using VVV9 = vector<VV9>;
#line 3 "library/KowerKoint/counting.hpp"

template <typename T>
struct Counting {
    vector<T> fact, ifact;

    Counting() {}
    Counting(ll n) {
        expand(n);
    }

    void expand(ll n) {
        ll sz = (ll)fact.size();
        if(sz > n) return;
        fact.resize(n+1);
        ifact.resize(n+1);
        fact[0] = 1;
        FOR(i, max(1LL, sz), n+1) fact[i] = fact[i-1] * i;
        ifact[n] = 1 / fact[n];
        for(ll i = n-1; i >= sz; i--) ifact[i] = ifact[i+1] * (i+1);
    }

    T permutation(ll n, ll r) {
        assert(n >= r);
        assert(r >= 0);
        expand(n);
        return fact[n] * ifact[n-r];
    }

    T combination(ll n, ll r) {
        assert(n >= r);
        assert(r >= 0);
        expand(n);
        return fact[n] * ifact[r] * ifact[n-r];
    }

    T stirling(ll n, ll k) {
        assert(n >= k);
        assert(k >= 0);
        if(n == 0) return 1;
        T res = 0;
        int sign = k%2? -1 : 1;
        expand(k);
        REP(i, k+1) {
            res += sign * ifact[i] * ifact[k-i] * T(i).pow(n);
            sign *= -1;
        }
        return res;
    }

    vector<vector<T>> stirling_table(ll n, ll k) {
        assert(n >= 0 && k >= 0);
        vector<vector<T>> res(n+1, vector<T>(k+1));
        res[0][0] = 1;
        FOR(i, 1, n+1) FOR(j, 1, k+1) {
            res[i][j] = res[i-1][j-1] + j * res[i-1][j];
        }
        return res;
    }

    T bell(ll n, ll k) {
        assert(n >= 0 && k >= 0);
        expand(k);
        vector<T> tmp(k+1);
        int sign = 1;
        tmp[0] = 1;
        FOR(i, 1, k+1) {
            sign *= -1;
            tmp[i] = tmp[i-1] + sign * ifact[i];
        }
        T res = 0;
        REP(i, k+1) {
            res += T(i).pow(n) * ifact[i] * tmp[k-i];
        }
        return res;
    }

    vector<vector<T>> partition_table(ll n) {
        assert(n >= 0);
        vector<vector<T>> res(n+1, vector<T>(n+1));
        REP(i, n+1) res[0][i] = 1;
        FOR(i, 1, n+1) FOR(j, 1, n+1) {
            res[i][j] = res[i][j-1] + (i<j? 0 : res[i-j][j]);
        }
        return res;
    }
};
#line 2 "Contests/Dummy/main.cpp"

/* #include "atcoder/all" */
/* using namespace atcoder; */
/* #include "KowerKoint/expansion/ac-library/all.hpp" */

void solve(){
    while(1) {
        int n, m; cin >> n >> m;
        if(!n) break;
        vector<tuple<int, int, int>> rec(m);
        REP(i, m) {
            int t, s, d; cin >> t >> s >> d; s--; d--;
            rec[i] = {t, s, d};
        }
        sort(ALL(rec));
        VI infected(n);
        infected[0] = 1;
        REP(i, m) {
            auto [t, s, d] = rec[i];
            infected[d] |= infected[s];
        }
        print(count(ALL(infected), 1));
    }
}

// generated by oj-template v4.7.2 (https://github.com/online-judge-tools/template-generator)
int main() {
    // Fasterize input/output script
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(100);
    // scanf/printf user should delete this fasterize input/output script

    int t = 1;
    //cin >> t; // comment out if solving multi testcase
    for(int testCase = 1;testCase <= t;++testCase){
        solve();
    }
    return 0;
}
accuracy: 1
time_ms: 270
memory_kb: 3720
final_rank: 19

code_snippet: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
typedef long long ll;
using namespace std;

void solve(int N, int M) {
    vector<tuple<int, int, int>> A(M);
    rep(i, M) {
        int id, u, v;
        cin >> id >> u >> v;
        u--, v--;
        A[i] = {id, u, v};
    }
    sort(A.begin(), A.end());

    vector<bool> flag(N);
    flag[0] = true;
    for (auto &[id, u, v] : A) {
        if (flag[u])
            flag[v] = true;
    }

    int ans = accumulate(flag.begin(), flag.end(), 0);
    cout << ans << "\n";
}

int main() {
    int N, M;
    while (cin >> N >> M, N)
        solve(N, M);

    return 0;
}
accuracy: 1
time_ms: 120
memory_kb: 3620
final_rank: 9