fork download
  1. #include <iostream>
  2. #include <queue>
  3. #include <string.h>
  4. using namespace std;
  5. struct E{
  6. long long int t;
  7. int from,to;
  8. bool operator<(const E& e1)const{
  9. return t>e1.t;
  10. }
  11. };
  12. void f(int n,int m){
  13. int memo[20003];
  14. memset(memo,0,sizeof(memo));
  15. memo[1]=1;
  16. priority_queue<E> pq;
  17. for(int i=0;i<m;i++){
  18. E e1;
  19. cin>>e1.t>>e1.from>>e1.to;
  20. pq.push(e1);
  21. }
  22. while(pq.size()>0){
  23. E e1=pq.top();
  24. pq.pop();
  25. if(memo[e1.from]==1)memo[e1.to]=1;
  26. }
  27. int ans=0;
  28. for(int i=1;i<=n;i++){
  29. ans+=memo[i];
  30. }
  31. cout<<ans<<endl;
  32. }
  33.  
  34.  
  35. int main() {
  36. int n,m;
  37. while(true){
  38. cin>>n>>m;
  39. if(n+m==0)break;
  40. f(n,m);
  41. }
  42. return 0;
  43. }
Success #stdin #stdout 0.01s 5296KB
stdin
3 2
1 1 2
2 2 3
3 2
2 3 2
1 2 1
0 0
stdout
3
1