人生列车

follow on!success!

导航

csu oj Infected Computer 1427

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <stdio.h>
 4 #define max 20005
 5 #define ll long long
 6 using namespace std;
 7 
 8 struct G{
 9     int from;
10     int to;
11     ll time;
12 }game[max];
13 
14 bool graf[max];
15 
16 bool cmp(G a,G b){
17     return a.time < b.time;
18 }
19 int main()
20 {
21     int n,m;
22     while(cin>>n>>m){
23         for(int i = 0;i < max;i++){
24             graf[i]=false;
25             game[i].time=game[i].from=game[i].to=0;
26         }
27         graf[1]=true;
28 
29         for(int i = 0;i < m;i++){
30             cin>>game[i].time>>game[i].from>>game[i].to;
31         }
32         sort(game,game+m,cmp);
33 
34         bool flag = false;
35         for(int i = 0;i < m;i++){
36             if(game[i].from==1){
37                 flag = true;
38                 //graf[game[i].to] = true;
39             }
40             if(flag&&graf[game[i].from]){
41                 graf[game[i].to] = true;
42             }
43         }
44         ll ans = 0;
45         for(int i = 1;i <= n;i++){
46             if(graf[i])ans++;
47         }
48         cout<<ans<<endl;
49     }
50     return 0;
51 }

如果非要给划分,我想应该是属于并查集一类的

posted on 2016-04-23 10:17  tianxia2s  阅读(193)  评论(0编辑  收藏  举报