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 }

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

时间: 2024-08-06 10:31:16

csu oj Infected Computer 1427的相关文章

CSU OJ 1112机器人的指令 (湖南省12年省赛题)

 Welcome to CSU Online Judge! 1112: 机器人的指令 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 274  Solved: 97 [Submit][Status][Web Board] Description 数轴原点有一个机器人.该机器人将执行一系列指令,你的任务是预测所有指令执行完毕之后它的位置. ·LEFT:往左移动一个单位 ·RIGHT: 往右移动一个单位 ·SAME AS i: 和第i 条执行相同的

CSU OJ 1120 病毒(湖南省第八届大学生计算机程序设计竞赛)

 1120: 病毒 Time Limit: 3 Sec  Memory Limit: 128 MB Submit: 146  Solved: 53 [Submit][Status][Web Board] Description 你有一个日志文件,里面记录着各种系统事件的详细信息.自然的,事件的时间戳按照严格递增顺序排列(不会有两个事件在完全相同的时刻发生). 遗憾的是,你的系统被病毒感染了,日志文件中混入了病毒生成的随机伪事件(但真实事件的相对顺序保持不变).备份的日志文件也被感染了,但由于

CSU OJ 1111 三家人 (湖南省第八届大学生计算机程序设计竞赛)

 1111: 三家人 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 356  Solved: 142 [Submit][Status][Web Board] Description 有三户人家共拥有一座花园,每户人家的太太均需帮忙整理花园.A 太太工作了5 天,B 太太则工作了4 天,才将花园整理完毕.C 太太因为正身怀六甲无法加入她们的行列,便出了90元.请问这笔钱如何分给A.B 二位太太较为恰当?A 应得多少元?90/(5+4)*5=$5

CSU OJ 1115 最短的名字(字典树——湖南省第八届大学生计算机程序设计竞赛)

 1115: 最短的名字 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 141  Solved: 56 [Submit][Status][Web Board] Description 在一个奇怪的村子中,很多人的名字都很长,比如aaaaa, bbb and abababab. 名字这么长,叫全名显然起来很不方便.所以村民之间一般只叫名字的前缀.比如叫'aaaaa'的时候可以只叫'aaa',因为没有第二个人名字的前三个字母是'aaa'.不过你不能

CSU OJ 三家人(湖南省第八届大学生计算机程序设计竞赛)

题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1111 这是道简单的数学题. <span style="font-size:18px;">#include<stdio.h> int main() { int t,z,d;; float x,y,k,s; scanf("%d",&t); int i; while (t--) { scanf("%f%f%d"

csu oj 1804: 有向无环图 (dfs回溯)

题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1804 中文题意就不说了. dfs从底到根回溯即可,看代码应该能清楚. 1 //#pragma comment(linker, "/STACK:102400000, 102400000") 2 #include <algorithm> 3 #include <iostream> 4 #include <cstdlib> 5 #include

csu oj 1811: Tree Intersection (启发式合并)

题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1811 给你一棵树,每个节点有一个颜色.问删除一条边形成两棵子树,两棵子树有多少种颜色是有相同的. 启发式合并,小的合并到大的中.类似的题目有http://codeforces.com/contest/600/problem/E 1 //#pragma comment(linker, "/STACK:102400000, 102400000") 2 #include <a

CSU OJ 1340 A Sample Problem

Description My girlfriend loves 7 very much, she thinks it is lucky! If an integer contains one or more 7, she will think it is lucky too! Input The first line has one integer T (1 <= T <= 100), means there are T test cases.    For each test case, t

CSU OJ PID=1514: Packs 超大背包问题,折半枚举+二分查找。

1514: Packs Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 61  Solved: 4[Submit][Status][Web Board] Description Give you n packs, each of it has a value v and a weight w. Now you should find some packs, and the total of these value is max, total of