#include "train.h"
#include<bits/stdc++.h>
using namespace std;
int n,m;
vector<int> point_to[5003];
int ori_outdeg[5003]={};
int temp_outdeg[5003];
bool loop[5003];
bool temp_loop[5003];
int cou_loop=0,cou_temp_loop;
bool fin_res[5003];
bool getreach()
{
queue<int> q;
int tt;
for(int i=0;i<n;i++) temp_outdeg[i]=ori_outdeg[i];
for(int i=0;i<n;i++) temp_loop[i]=false;
cou_temp_loop=0;
for(int j=0;j<n;j++)
{
if(!loop[j]) continue;
for(int i=0;i<point_to[j].size();i++)
{
temp_outdeg[point_to[j][i]]--;
if(!temp_outdeg[point_to[j][i]]) q.push(point_to[j][i]);
}
}
while(!q.empty())
{
tt=q.front();
q.pop();
temp_loop[tt]=true;
if(loop[tt])
{
cou_temp_loop++;
continue;
}
for(int i=0;i<point_to[tt].size();i++)
{
temp_outdeg[point_to[tt][i]]--;
if(!temp_outdeg[point_to[tt][i]]) q.push(point_to[tt][i]);
}
}
for(int i=0;i<n;i++) {loop[i]=min(loop[i],temp_loop[i]);fin_res[i]=temp_loop[i];}
int temp2=cou_loop;
cou_loop=cou_temp_loop;
return temp2==cou_temp_loop;
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
std::vector<int> res(a.size(),1);
n=a.size();
m=u.size();
for(int i=0;i<m;i++)
{
point_to[v[i]].push_back(u[i]);
ori_outdeg[u[i]]++;
}
for(int i=0;i<n;i++) {loop[i]=r[i]; cou_loop+=r[i];}
for(int i=0;i<n;i++) if(a[i]) ori_outdeg[i]=1;
while(!getreach()) continue;
for(int i=0;i<n;i++)
{
res[i]=fin_res[i];
}
return res;
}
Compilation message
train.cpp: In function 'bool getreach()':
train.cpp:23:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for(int i=0;i<point_to[j].size();i++)
| ~^~~~~~~~~~~~~~~~~~~
train.cpp:40:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for(int i=0;i<point_to[tt].size();i++)
| ~^~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
760 KB |
Output is correct |
2 |
Correct |
6 ms |
716 KB |
Output is correct |
3 |
Correct |
6 ms |
716 KB |
Output is correct |
4 |
Correct |
6 ms |
764 KB |
Output is correct |
5 |
Correct |
7 ms |
836 KB |
Output is correct |
6 |
Correct |
6 ms |
844 KB |
Output is correct |
7 |
Correct |
6 ms |
828 KB |
Output is correct |
8 |
Correct |
6 ms |
716 KB |
Output is correct |
9 |
Correct |
5 ms |
716 KB |
Output is correct |
10 |
Correct |
4 ms |
716 KB |
Output is correct |
11 |
Correct |
4 ms |
716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
95 ms |
1100 KB |
Output is correct |
2 |
Correct |
172 ms |
1108 KB |
Output is correct |
3 |
Correct |
229 ms |
1100 KB |
Output is correct |
4 |
Correct |
8 ms |
1100 KB |
Output is correct |
5 |
Correct |
12 ms |
1100 KB |
Output is correct |
6 |
Correct |
12 ms |
1092 KB |
Output is correct |
7 |
Correct |
11 ms |
1064 KB |
Output is correct |
8 |
Correct |
10 ms |
1084 KB |
Output is correct |
9 |
Correct |
7 ms |
948 KB |
Output is correct |
10 |
Correct |
7 ms |
1060 KB |
Output is correct |
11 |
Correct |
7 ms |
972 KB |
Output is correct |
12 |
Correct |
7 ms |
972 KB |
Output is correct |
13 |
Correct |
8 ms |
1100 KB |
Output is correct |
14 |
Correct |
8 ms |
1100 KB |
Output is correct |
15 |
Correct |
8 ms |
1044 KB |
Output is correct |
16 |
Correct |
8 ms |
1100 KB |
Output is correct |
17 |
Correct |
8 ms |
1100 KB |
Output is correct |
18 |
Correct |
237 ms |
880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
972 KB |
Output is correct |
2 |
Correct |
7 ms |
972 KB |
Output is correct |
3 |
Correct |
8 ms |
1000 KB |
Output is correct |
4 |
Correct |
8 ms |
992 KB |
Output is correct |
5 |
Correct |
8 ms |
972 KB |
Output is correct |
6 |
Correct |
8 ms |
988 KB |
Output is correct |
7 |
Correct |
8 ms |
1024 KB |
Output is correct |
8 |
Correct |
7 ms |
972 KB |
Output is correct |
9 |
Correct |
10 ms |
976 KB |
Output is correct |
10 |
Correct |
10 ms |
1100 KB |
Output is correct |
11 |
Correct |
8 ms |
1100 KB |
Output is correct |
12 |
Correct |
10 ms |
996 KB |
Output is correct |
13 |
Correct |
8 ms |
972 KB |
Output is correct |
14 |
Correct |
10 ms |
972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
1100 KB |
Output is correct |
2 |
Correct |
8 ms |
1100 KB |
Output is correct |
3 |
Correct |
8 ms |
1032 KB |
Output is correct |
4 |
Correct |
7 ms |
972 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
4 ms |
716 KB |
Output is correct |
7 |
Correct |
5 ms |
844 KB |
Output is correct |
8 |
Correct |
7 ms |
844 KB |
Output is correct |
9 |
Correct |
5 ms |
836 KB |
Output is correct |
10 |
Correct |
2 ms |
460 KB |
Output is correct |
11 |
Correct |
6 ms |
716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
760 KB |
Output is correct |
2 |
Correct |
6 ms |
716 KB |
Output is correct |
3 |
Correct |
6 ms |
716 KB |
Output is correct |
4 |
Correct |
6 ms |
764 KB |
Output is correct |
5 |
Correct |
7 ms |
836 KB |
Output is correct |
6 |
Correct |
6 ms |
844 KB |
Output is correct |
7 |
Correct |
6 ms |
828 KB |
Output is correct |
8 |
Correct |
6 ms |
716 KB |
Output is correct |
9 |
Correct |
5 ms |
716 KB |
Output is correct |
10 |
Correct |
4 ms |
716 KB |
Output is correct |
11 |
Correct |
4 ms |
716 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
0 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
95 ms |
1100 KB |
Output is correct |
33 |
Correct |
172 ms |
1108 KB |
Output is correct |
34 |
Correct |
229 ms |
1100 KB |
Output is correct |
35 |
Correct |
8 ms |
1100 KB |
Output is correct |
36 |
Correct |
12 ms |
1100 KB |
Output is correct |
37 |
Correct |
12 ms |
1092 KB |
Output is correct |
38 |
Correct |
11 ms |
1064 KB |
Output is correct |
39 |
Correct |
10 ms |
1084 KB |
Output is correct |
40 |
Correct |
7 ms |
948 KB |
Output is correct |
41 |
Correct |
7 ms |
1060 KB |
Output is correct |
42 |
Correct |
7 ms |
972 KB |
Output is correct |
43 |
Correct |
7 ms |
972 KB |
Output is correct |
44 |
Correct |
8 ms |
1100 KB |
Output is correct |
45 |
Correct |
8 ms |
1100 KB |
Output is correct |
46 |
Correct |
8 ms |
1044 KB |
Output is correct |
47 |
Correct |
8 ms |
1100 KB |
Output is correct |
48 |
Correct |
8 ms |
1100 KB |
Output is correct |
49 |
Correct |
237 ms |
880 KB |
Output is correct |
50 |
Correct |
7 ms |
972 KB |
Output is correct |
51 |
Correct |
7 ms |
972 KB |
Output is correct |
52 |
Correct |
8 ms |
1000 KB |
Output is correct |
53 |
Correct |
8 ms |
992 KB |
Output is correct |
54 |
Correct |
8 ms |
972 KB |
Output is correct |
55 |
Correct |
8 ms |
988 KB |
Output is correct |
56 |
Correct |
8 ms |
1024 KB |
Output is correct |
57 |
Correct |
7 ms |
972 KB |
Output is correct |
58 |
Correct |
10 ms |
976 KB |
Output is correct |
59 |
Correct |
10 ms |
1100 KB |
Output is correct |
60 |
Correct |
8 ms |
1100 KB |
Output is correct |
61 |
Correct |
10 ms |
996 KB |
Output is correct |
62 |
Correct |
8 ms |
972 KB |
Output is correct |
63 |
Correct |
10 ms |
972 KB |
Output is correct |
64 |
Correct |
8 ms |
1100 KB |
Output is correct |
65 |
Correct |
8 ms |
1100 KB |
Output is correct |
66 |
Correct |
8 ms |
1032 KB |
Output is correct |
67 |
Correct |
7 ms |
972 KB |
Output is correct |
68 |
Correct |
1 ms |
460 KB |
Output is correct |
69 |
Correct |
4 ms |
716 KB |
Output is correct |
70 |
Correct |
5 ms |
844 KB |
Output is correct |
71 |
Correct |
7 ms |
844 KB |
Output is correct |
72 |
Correct |
5 ms |
836 KB |
Output is correct |
73 |
Correct |
2 ms |
460 KB |
Output is correct |
74 |
Correct |
6 ms |
716 KB |
Output is correct |
75 |
Correct |
146 ms |
1112 KB |
Output is correct |
76 |
Correct |
171 ms |
1120 KB |
Output is correct |
77 |
Correct |
238 ms |
1100 KB |
Output is correct |
78 |
Correct |
241 ms |
1092 KB |
Output is correct |
79 |
Correct |
243 ms |
1228 KB |
Output is correct |
80 |
Correct |
8 ms |
1100 KB |
Output is correct |
81 |
Correct |
10 ms |
972 KB |
Output is correct |
82 |
Correct |
9 ms |
972 KB |
Output is correct |
83 |
Correct |
10 ms |
1100 KB |
Output is correct |
84 |
Correct |
11 ms |
1004 KB |
Output is correct |
85 |
Correct |
9 ms |
1076 KB |
Output is correct |
86 |
Correct |
12 ms |
1100 KB |
Output is correct |
87 |
Correct |
8 ms |
972 KB |
Output is correct |
88 |
Correct |
19 ms |
992 KB |
Output is correct |
89 |
Correct |
8 ms |
972 KB |
Output is correct |
90 |
Correct |
18 ms |
1084 KB |
Output is correct |
91 |
Correct |
21 ms |
1096 KB |
Output is correct |
92 |
Correct |
31 ms |
1092 KB |
Output is correct |
93 |
Correct |
27 ms |
984 KB |
Output is correct |
94 |
Correct |
26 ms |
1100 KB |
Output is correct |
95 |
Correct |
28 ms |
972 KB |
Output is correct |
96 |
Correct |
65 ms |
1028 KB |
Output is correct |
97 |
Correct |
236 ms |
1080 KB |
Output is correct |
98 |
Correct |
350 ms |
1060 KB |
Output is correct |
99 |
Correct |
338 ms |
1048 KB |
Output is correct |
100 |
Correct |
234 ms |
844 KB |
Output is correct |