#include <stdio.h>
#include <queue>
#include <vector>
using namespace std;
#define pb push_back
const int N=5050;
vector<int> R[N];
int deg[N],in[N];
bool was[N],vis[N],A[N];
void AddEdge(int u, int v){ R[v].pb(u);deg[u]++;}
void DelNode(int u){ for(int i=0;i<R[u].size();i++) deg[R[u][i]]--;was[u]=1;}
void init(int n){ for(int i=1;i<=n;i++) vis[i]=0;}
queue<int> q;
vector<int> st;
void BFS(int n, bool mod)
{
init(n);
int i;
for(i=1;i<=n;i++) if(!was[i]) in[i]=(A[i]==mod)?1:deg[i];
for(i=0;i<st.size();i++) vis[st[i]]=1,q.push(st[i]);
while(q.size())
{
int u=q.front();
q.pop();
for(i=0;i<R[u].size();i++)
{
int v=R[u][i];
if(vis[v] || was[v]) continue;
in[v]--;
if(!in[v])
{
vis[v]=1;
q.push(v);
}
}
}
}
vector<int> ch;
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v)
{
int n=a.size(),i,m=v.size();
for(i=0;i<n;i++) A[i+1]=a[i];
for(i=0;i<n;i++) if(r[i]) ch.pb(i+1);
for(i=0;i<m;i++) AddEdge(u[i]+1,v[i]+1);
bool done;
do
{
st.clear();
for(i=0;i<ch.size();i++) if(!was[ch[i]]) st.pb(ch[i]);
BFS(n,1);
st.clear();
for(i=1;i<=n;i++) if(!was[i] && !vis[i]) st.pb(i);
BFS(n,0);
done=0;
for(i=1;i<=n;i++) if(!was[i] && vis[i]) done=1,DelNode(i);
}while(done);
vector<int> ans;
for(i=1;i<=n;i++) ans.pb(!was[i]);
return ans;
}
/*int main()
{
int n,m,i,x,y;
vector<int> a,r,u,v;
scanf("%i %i",&n,&m);
for(i=0;i<n;i++) scanf("%i",&x),a.pb(x);
for(i=0;i<n;i++) scanf("%i",&x),r.pb(x);
for(i=0;i<m;i++) scanf("%i %i",&x,&y),u.pb(x),v.pb(y);
vector<int> ans=who_wins(a,r,u,v);
for(i=0;i<ans.size();i++) printf("%i ",ans[i]);printf("\n");
return 0;
}*/
Compilation message
train.cpp: In function 'void DelNode(int)':
train.cpp:11:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
void DelNode(int u){ for(int i=0;i<R[u].size();i++) deg[R[u][i]]--;was[u]=1;}
~^~~~~~~~~~~~
train.cpp: In function 'void BFS(int, bool)':
train.cpp:20:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0;i<st.size();i++) vis[st[i]]=1,q.push(st[i]);
~^~~~~~~~~~
train.cpp:25:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0;i<R[u].size();i++)
~^~~~~~~~~~~~
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:49:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0;i<ch.size();i++) if(!was[ch[i]]) st.pb(ch[i]);
~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
1016 KB |
Output is correct |
2 |
Correct |
10 ms |
1232 KB |
Output is correct |
3 |
Correct |
9 ms |
1232 KB |
Output is correct |
4 |
Correct |
9 ms |
1372 KB |
Output is correct |
5 |
Correct |
8 ms |
1456 KB |
Output is correct |
6 |
Correct |
9 ms |
1728 KB |
Output is correct |
7 |
Correct |
7 ms |
1808 KB |
Output is correct |
8 |
Correct |
11 ms |
1892 KB |
Output is correct |
9 |
Correct |
7 ms |
2080 KB |
Output is correct |
10 |
Correct |
8 ms |
2080 KB |
Output is correct |
11 |
Correct |
11 ms |
2120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2120 KB |
Output is correct |
2 |
Correct |
2 ms |
2120 KB |
Output is correct |
3 |
Correct |
4 ms |
2120 KB |
Output is correct |
4 |
Correct |
3 ms |
2120 KB |
Output is correct |
5 |
Correct |
3 ms |
2120 KB |
Output is correct |
6 |
Correct |
2 ms |
2120 KB |
Output is correct |
7 |
Correct |
3 ms |
2120 KB |
Output is correct |
8 |
Correct |
3 ms |
2120 KB |
Output is correct |
9 |
Correct |
3 ms |
2120 KB |
Output is correct |
10 |
Correct |
3 ms |
2120 KB |
Output is correct |
11 |
Correct |
2 ms |
2120 KB |
Output is correct |
12 |
Correct |
2 ms |
2120 KB |
Output is correct |
13 |
Correct |
2 ms |
2120 KB |
Output is correct |
14 |
Correct |
2 ms |
2120 KB |
Output is correct |
15 |
Correct |
2 ms |
2120 KB |
Output is correct |
16 |
Correct |
3 ms |
2120 KB |
Output is correct |
17 |
Correct |
3 ms |
2120 KB |
Output is correct |
18 |
Correct |
2 ms |
2120 KB |
Output is correct |
19 |
Correct |
2 ms |
2120 KB |
Output is correct |
20 |
Correct |
3 ms |
2120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
105 ms |
2700 KB |
Output is correct |
2 |
Correct |
195 ms |
2940 KB |
Output is correct |
3 |
Correct |
326 ms |
3164 KB |
Output is correct |
4 |
Correct |
13 ms |
3372 KB |
Output is correct |
5 |
Correct |
14 ms |
3580 KB |
Output is correct |
6 |
Correct |
12 ms |
3676 KB |
Output is correct |
7 |
Correct |
12 ms |
4004 KB |
Output is correct |
8 |
Correct |
11 ms |
4208 KB |
Output is correct |
9 |
Correct |
13 ms |
4392 KB |
Output is correct |
10 |
Correct |
12 ms |
4476 KB |
Output is correct |
11 |
Correct |
15 ms |
4676 KB |
Output is correct |
12 |
Correct |
10 ms |
4908 KB |
Output is correct |
13 |
Correct |
13 ms |
5176 KB |
Output is correct |
14 |
Correct |
12 ms |
5384 KB |
Output is correct |
15 |
Correct |
12 ms |
5592 KB |
Output is correct |
16 |
Correct |
25 ms |
5672 KB |
Output is correct |
17 |
Correct |
13 ms |
5992 KB |
Output is correct |
18 |
Correct |
481 ms |
5992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
6204 KB |
Output is correct |
2 |
Correct |
11 ms |
6364 KB |
Output is correct |
3 |
Correct |
10 ms |
6672 KB |
Output is correct |
4 |
Correct |
11 ms |
6860 KB |
Output is correct |
5 |
Correct |
11 ms |
7088 KB |
Output is correct |
6 |
Correct |
11 ms |
7164 KB |
Output is correct |
7 |
Correct |
11 ms |
7364 KB |
Output is correct |
8 |
Correct |
11 ms |
7564 KB |
Output is correct |
9 |
Correct |
15 ms |
7760 KB |
Output is correct |
10 |
Correct |
13 ms |
8072 KB |
Output is correct |
11 |
Correct |
17 ms |
8280 KB |
Output is correct |
12 |
Correct |
13 ms |
8488 KB |
Output is correct |
13 |
Correct |
12 ms |
8804 KB |
Output is correct |
14 |
Correct |
15 ms |
8816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
9132 KB |
Output is correct |
2 |
Correct |
18 ms |
9340 KB |
Output is correct |
3 |
Correct |
12 ms |
9552 KB |
Output is correct |
4 |
Correct |
10 ms |
9632 KB |
Output is correct |
5 |
Correct |
3 ms |
9632 KB |
Output is correct |
6 |
Correct |
8 ms |
9632 KB |
Output is correct |
7 |
Correct |
8 ms |
9672 KB |
Output is correct |
8 |
Correct |
12 ms |
9896 KB |
Output is correct |
9 |
Correct |
8 ms |
9956 KB |
Output is correct |
10 |
Correct |
5 ms |
9956 KB |
Output is correct |
11 |
Correct |
10 ms |
10136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
1016 KB |
Output is correct |
2 |
Correct |
10 ms |
1232 KB |
Output is correct |
3 |
Correct |
9 ms |
1232 KB |
Output is correct |
4 |
Correct |
9 ms |
1372 KB |
Output is correct |
5 |
Correct |
8 ms |
1456 KB |
Output is correct |
6 |
Correct |
9 ms |
1728 KB |
Output is correct |
7 |
Correct |
7 ms |
1808 KB |
Output is correct |
8 |
Correct |
11 ms |
1892 KB |
Output is correct |
9 |
Correct |
7 ms |
2080 KB |
Output is correct |
10 |
Correct |
8 ms |
2080 KB |
Output is correct |
11 |
Correct |
11 ms |
2120 KB |
Output is correct |
12 |
Correct |
3 ms |
2120 KB |
Output is correct |
13 |
Correct |
2 ms |
2120 KB |
Output is correct |
14 |
Correct |
4 ms |
2120 KB |
Output is correct |
15 |
Correct |
3 ms |
2120 KB |
Output is correct |
16 |
Correct |
3 ms |
2120 KB |
Output is correct |
17 |
Correct |
2 ms |
2120 KB |
Output is correct |
18 |
Correct |
3 ms |
2120 KB |
Output is correct |
19 |
Correct |
3 ms |
2120 KB |
Output is correct |
20 |
Correct |
3 ms |
2120 KB |
Output is correct |
21 |
Correct |
3 ms |
2120 KB |
Output is correct |
22 |
Correct |
2 ms |
2120 KB |
Output is correct |
23 |
Correct |
2 ms |
2120 KB |
Output is correct |
24 |
Correct |
2 ms |
2120 KB |
Output is correct |
25 |
Correct |
2 ms |
2120 KB |
Output is correct |
26 |
Correct |
2 ms |
2120 KB |
Output is correct |
27 |
Correct |
3 ms |
2120 KB |
Output is correct |
28 |
Correct |
3 ms |
2120 KB |
Output is correct |
29 |
Correct |
2 ms |
2120 KB |
Output is correct |
30 |
Correct |
2 ms |
2120 KB |
Output is correct |
31 |
Correct |
3 ms |
2120 KB |
Output is correct |
32 |
Correct |
105 ms |
2700 KB |
Output is correct |
33 |
Correct |
195 ms |
2940 KB |
Output is correct |
34 |
Correct |
326 ms |
3164 KB |
Output is correct |
35 |
Correct |
13 ms |
3372 KB |
Output is correct |
36 |
Correct |
14 ms |
3580 KB |
Output is correct |
37 |
Correct |
12 ms |
3676 KB |
Output is correct |
38 |
Correct |
12 ms |
4004 KB |
Output is correct |
39 |
Correct |
11 ms |
4208 KB |
Output is correct |
40 |
Correct |
13 ms |
4392 KB |
Output is correct |
41 |
Correct |
12 ms |
4476 KB |
Output is correct |
42 |
Correct |
15 ms |
4676 KB |
Output is correct |
43 |
Correct |
10 ms |
4908 KB |
Output is correct |
44 |
Correct |
13 ms |
5176 KB |
Output is correct |
45 |
Correct |
12 ms |
5384 KB |
Output is correct |
46 |
Correct |
12 ms |
5592 KB |
Output is correct |
47 |
Correct |
25 ms |
5672 KB |
Output is correct |
48 |
Correct |
13 ms |
5992 KB |
Output is correct |
49 |
Correct |
481 ms |
5992 KB |
Output is correct |
50 |
Correct |
9 ms |
6204 KB |
Output is correct |
51 |
Correct |
11 ms |
6364 KB |
Output is correct |
52 |
Correct |
10 ms |
6672 KB |
Output is correct |
53 |
Correct |
11 ms |
6860 KB |
Output is correct |
54 |
Correct |
11 ms |
7088 KB |
Output is correct |
55 |
Correct |
11 ms |
7164 KB |
Output is correct |
56 |
Correct |
11 ms |
7364 KB |
Output is correct |
57 |
Correct |
11 ms |
7564 KB |
Output is correct |
58 |
Correct |
15 ms |
7760 KB |
Output is correct |
59 |
Correct |
13 ms |
8072 KB |
Output is correct |
60 |
Correct |
17 ms |
8280 KB |
Output is correct |
61 |
Correct |
13 ms |
8488 KB |
Output is correct |
62 |
Correct |
12 ms |
8804 KB |
Output is correct |
63 |
Correct |
15 ms |
8816 KB |
Output is correct |
64 |
Correct |
18 ms |
9132 KB |
Output is correct |
65 |
Correct |
18 ms |
9340 KB |
Output is correct |
66 |
Correct |
12 ms |
9552 KB |
Output is correct |
67 |
Correct |
10 ms |
9632 KB |
Output is correct |
68 |
Correct |
3 ms |
9632 KB |
Output is correct |
69 |
Correct |
8 ms |
9632 KB |
Output is correct |
70 |
Correct |
8 ms |
9672 KB |
Output is correct |
71 |
Correct |
12 ms |
9896 KB |
Output is correct |
72 |
Correct |
8 ms |
9956 KB |
Output is correct |
73 |
Correct |
5 ms |
9956 KB |
Output is correct |
74 |
Correct |
10 ms |
10136 KB |
Output is correct |
75 |
Correct |
134 ms |
10572 KB |
Output is correct |
76 |
Correct |
283 ms |
10820 KB |
Output is correct |
77 |
Correct |
332 ms |
11004 KB |
Output is correct |
78 |
Correct |
336 ms |
11240 KB |
Output is correct |
79 |
Correct |
310 ms |
11544 KB |
Output is correct |
80 |
Correct |
14 ms |
11544 KB |
Output is correct |
81 |
Correct |
15 ms |
11860 KB |
Output is correct |
82 |
Correct |
20 ms |
11940 KB |
Output is correct |
83 |
Correct |
21 ms |
12276 KB |
Output is correct |
84 |
Correct |
14 ms |
12360 KB |
Output is correct |
85 |
Correct |
13 ms |
12568 KB |
Output is correct |
86 |
Correct |
14 ms |
12900 KB |
Output is correct |
87 |
Correct |
18 ms |
13236 KB |
Output is correct |
88 |
Correct |
18 ms |
13348 KB |
Output is correct |
89 |
Correct |
12 ms |
13560 KB |
Output is correct |
90 |
Correct |
22 ms |
13672 KB |
Output is correct |
91 |
Correct |
19 ms |
14016 KB |
Output is correct |
92 |
Correct |
27 ms |
14216 KB |
Output is correct |
93 |
Correct |
33 ms |
14300 KB |
Output is correct |
94 |
Correct |
31 ms |
14636 KB |
Output is correct |
95 |
Correct |
43 ms |
14828 KB |
Output is correct |
96 |
Correct |
99 ms |
14924 KB |
Output is correct |
97 |
Correct |
370 ms |
15240 KB |
Output is correct |
98 |
Correct |
613 ms |
15448 KB |
Output is correct |
99 |
Correct |
620 ms |
15648 KB |
Output is correct |
100 |
Correct |
459 ms |
15648 KB |
Output is correct |