#include "train.h"
#include<bits/stdc++.h>
using namespace std;
const int nmax=5e3+42;
int who[nmax];
int charge[nmax];
vector<int> prv[nmax];
bool on[nmax];
int n;
int outp[nmax];
bool been[nmax];
int owner;
int deg[nmax];
void dfs(int node)
{
//cout<<"dfs "<<node<<" "<<owner<<endl;
if(been[node])return;
been[node]=1;
for(auto w:prv[node])
{
//cout<<"w= "<<w<<" node= "<<node<<endl;
if(who[w]==owner)dfs(w);
else
{
deg[w]--;
if(deg[w]==0)dfs(w);
}
}
}
vector<int> f(int person,vector<int> start)
{
for(int i=1;i<=n;i++)been[i]=0;
owner=person;
for(auto w:start)
{
dfs(w);
}
vector<int> ret={};
for(int i=1;i<=n;i++)
if(been[i])ret.push_back(i);
//cout<<"f "<<person<<" start: ";for(auto w:start)cout<<w<<" ";cout<<" ret: ";for(auto w:ret)cout<<w<<" ";cout<<endl;
return ret;
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
n=a.size();
for(int i=1;i<=n;i++)who[i]=a[i-1];
for(int i=1;i<=n;i++)charge[i]=r[i-1];
for(int i=1;i<=n;i++)on[i]=1;
while(1)
{
for(int i=1;i<=n;i++)
{
prv[i]={};
deg[i]=0;
}
for(int i=0;i<u.size();i++)
{
int from=u[i]+1;
int to=v[i]+1;
if(on[from]&&on[to])
{
prv[to].push_back(from);
//cout<<"prv "<<to<<" "<<from<<endl;
deg[from]++;
}
}
vector<int> remain={},charges={};
for(int i=1;i<=n;i++)
if(on[i])
{
remain.push_back(i);
if(charge[i])charges.push_back(i);
}
vector<int> help=f(1,charges);
if(help==remain)
{
for(auto w:help)
outp[w]=1;
break;
}
else
{
vector<int> other={};
int j=0;
for(auto w:remain)
{
if(j<help.size()&&w==help[j])j++;
else other.push_back(w);
}
help=f(0,other);
for(auto w:help)
{
on[w]=0;
}
}
}
vector<int> ret={};
for(int i=1;i<=n;i++)
ret.push_back(outp[i]);
return ret;
}
/*
int main() {
int n, m;
assert(2 == scanf("%d %d", &n, &m));
vector<int> a(n), r(n), u(m), v(m);
for(int i = 0; i < n; i++)
assert(1 == scanf("%d", &a[i]));
for(int i = 0; i < n; i++)
assert(1 == scanf("%d", &r[i]));
for(int i = 0; i < m; i++)
assert(2 == scanf("%d %d", &u[i], &v[i]));
vector<int> res = who_wins(a, r, u, v);
for(int i = 0; i < (int)res.size(); i++)
printf(i ? " %d" : "%d", res[i]);
printf("\n");
return 0;
}
*/
Compilation message
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:77:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | for(int i=0;i<u.size();i++)
| ~^~~~~~~~~
train.cpp:116:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
116 | if(j<help.size()&&w==help[j])j++;
| ~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
844 KB |
Output is correct |
2 |
Correct |
6 ms |
896 KB |
Output is correct |
3 |
Correct |
6 ms |
844 KB |
Output is correct |
4 |
Correct |
8 ms |
892 KB |
Output is correct |
5 |
Correct |
5 ms |
844 KB |
Output is correct |
6 |
Correct |
6 ms |
844 KB |
Output is correct |
7 |
Correct |
5 ms |
964 KB |
Output is correct |
8 |
Correct |
7 ms |
900 KB |
Output is correct |
9 |
Correct |
5 ms |
844 KB |
Output is correct |
10 |
Correct |
5 ms |
844 KB |
Output is correct |
11 |
Correct |
4 ms |
904 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 |
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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
238 ms |
1420 KB |
Output is correct |
2 |
Correct |
399 ms |
1408 KB |
Output is correct |
3 |
Correct |
545 ms |
1412 KB |
Output is correct |
4 |
Correct |
8 ms |
1228 KB |
Output is correct |
5 |
Correct |
10 ms |
1296 KB |
Output is correct |
6 |
Correct |
10 ms |
1100 KB |
Output is correct |
7 |
Correct |
9 ms |
1228 KB |
Output is correct |
8 |
Correct |
8 ms |
1100 KB |
Output is correct |
9 |
Correct |
8 ms |
1108 KB |
Output is correct |
10 |
Correct |
8 ms |
1100 KB |
Output is correct |
11 |
Correct |
8 ms |
1100 KB |
Output is correct |
12 |
Correct |
7 ms |
1152 KB |
Output is correct |
13 |
Correct |
8 ms |
1280 KB |
Output is correct |
14 |
Correct |
8 ms |
1228 KB |
Output is correct |
15 |
Correct |
8 ms |
1228 KB |
Output is correct |
16 |
Correct |
8 ms |
1228 KB |
Output is correct |
17 |
Correct |
10 ms |
1248 KB |
Output is correct |
18 |
Correct |
714 ms |
1124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
1092 KB |
Output is correct |
2 |
Correct |
8 ms |
1100 KB |
Output is correct |
3 |
Correct |
8 ms |
1128 KB |
Output is correct |
4 |
Correct |
8 ms |
1100 KB |
Output is correct |
5 |
Correct |
12 ms |
1124 KB |
Output is correct |
6 |
Correct |
8 ms |
1100 KB |
Output is correct |
7 |
Correct |
8 ms |
1100 KB |
Output is correct |
8 |
Correct |
8 ms |
1116 KB |
Output is correct |
9 |
Correct |
8 ms |
1108 KB |
Output is correct |
10 |
Correct |
8 ms |
1228 KB |
Output is correct |
11 |
Correct |
8 ms |
1228 KB |
Output is correct |
12 |
Correct |
8 ms |
1228 KB |
Output is correct |
13 |
Correct |
9 ms |
1252 KB |
Output is correct |
14 |
Correct |
8 ms |
1108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
1228 KB |
Output is correct |
2 |
Correct |
8 ms |
1252 KB |
Output is correct |
3 |
Correct |
10 ms |
1100 KB |
Output is correct |
4 |
Correct |
7 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
432 KB |
Output is correct |
6 |
Correct |
4 ms |
844 KB |
Output is correct |
7 |
Correct |
6 ms |
844 KB |
Output is correct |
8 |
Correct |
6 ms |
844 KB |
Output is correct |
9 |
Correct |
6 ms |
844 KB |
Output is correct |
10 |
Correct |
2 ms |
460 KB |
Output is correct |
11 |
Correct |
5 ms |
844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
844 KB |
Output is correct |
2 |
Correct |
6 ms |
896 KB |
Output is correct |
3 |
Correct |
6 ms |
844 KB |
Output is correct |
4 |
Correct |
8 ms |
892 KB |
Output is correct |
5 |
Correct |
5 ms |
844 KB |
Output is correct |
6 |
Correct |
6 ms |
844 KB |
Output is correct |
7 |
Correct |
5 ms |
964 KB |
Output is correct |
8 |
Correct |
7 ms |
900 KB |
Output is correct |
9 |
Correct |
5 ms |
844 KB |
Output is correct |
10 |
Correct |
5 ms |
844 KB |
Output is correct |
11 |
Correct |
4 ms |
904 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 |
1 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 |
238 ms |
1420 KB |
Output is correct |
33 |
Correct |
399 ms |
1408 KB |
Output is correct |
34 |
Correct |
545 ms |
1412 KB |
Output is correct |
35 |
Correct |
8 ms |
1228 KB |
Output is correct |
36 |
Correct |
10 ms |
1296 KB |
Output is correct |
37 |
Correct |
10 ms |
1100 KB |
Output is correct |
38 |
Correct |
9 ms |
1228 KB |
Output is correct |
39 |
Correct |
8 ms |
1100 KB |
Output is correct |
40 |
Correct |
8 ms |
1108 KB |
Output is correct |
41 |
Correct |
8 ms |
1100 KB |
Output is correct |
42 |
Correct |
8 ms |
1100 KB |
Output is correct |
43 |
Correct |
7 ms |
1152 KB |
Output is correct |
44 |
Correct |
8 ms |
1280 KB |
Output is correct |
45 |
Correct |
8 ms |
1228 KB |
Output is correct |
46 |
Correct |
8 ms |
1228 KB |
Output is correct |
47 |
Correct |
8 ms |
1228 KB |
Output is correct |
48 |
Correct |
10 ms |
1248 KB |
Output is correct |
49 |
Correct |
714 ms |
1124 KB |
Output is correct |
50 |
Correct |
7 ms |
1092 KB |
Output is correct |
51 |
Correct |
8 ms |
1100 KB |
Output is correct |
52 |
Correct |
8 ms |
1128 KB |
Output is correct |
53 |
Correct |
8 ms |
1100 KB |
Output is correct |
54 |
Correct |
12 ms |
1124 KB |
Output is correct |
55 |
Correct |
8 ms |
1100 KB |
Output is correct |
56 |
Correct |
8 ms |
1100 KB |
Output is correct |
57 |
Correct |
8 ms |
1116 KB |
Output is correct |
58 |
Correct |
8 ms |
1108 KB |
Output is correct |
59 |
Correct |
8 ms |
1228 KB |
Output is correct |
60 |
Correct |
8 ms |
1228 KB |
Output is correct |
61 |
Correct |
8 ms |
1228 KB |
Output is correct |
62 |
Correct |
9 ms |
1252 KB |
Output is correct |
63 |
Correct |
8 ms |
1108 KB |
Output is correct |
64 |
Correct |
8 ms |
1228 KB |
Output is correct |
65 |
Correct |
8 ms |
1252 KB |
Output is correct |
66 |
Correct |
10 ms |
1100 KB |
Output is correct |
67 |
Correct |
7 ms |
1100 KB |
Output is correct |
68 |
Correct |
1 ms |
432 KB |
Output is correct |
69 |
Correct |
4 ms |
844 KB |
Output is correct |
70 |
Correct |
6 ms |
844 KB |
Output is correct |
71 |
Correct |
6 ms |
844 KB |
Output is correct |
72 |
Correct |
6 ms |
844 KB |
Output is correct |
73 |
Correct |
2 ms |
460 KB |
Output is correct |
74 |
Correct |
5 ms |
844 KB |
Output is correct |
75 |
Correct |
330 ms |
1348 KB |
Output is correct |
76 |
Correct |
427 ms |
1500 KB |
Output is correct |
77 |
Correct |
576 ms |
1400 KB |
Output is correct |
78 |
Correct |
567 ms |
1400 KB |
Output is correct |
79 |
Correct |
577 ms |
1396 KB |
Output is correct |
80 |
Correct |
9 ms |
1228 KB |
Output is correct |
81 |
Correct |
9 ms |
1100 KB |
Output is correct |
82 |
Correct |
10 ms |
1100 KB |
Output is correct |
83 |
Correct |
10 ms |
1228 KB |
Output is correct |
84 |
Correct |
12 ms |
1228 KB |
Output is correct |
85 |
Correct |
12 ms |
1128 KB |
Output is correct |
86 |
Correct |
14 ms |
1260 KB |
Output is correct |
87 |
Correct |
8 ms |
1100 KB |
Output is correct |
88 |
Correct |
14 ms |
1124 KB |
Output is correct |
89 |
Correct |
11 ms |
1128 KB |
Output is correct |
90 |
Correct |
19 ms |
1184 KB |
Output is correct |
91 |
Correct |
18 ms |
1192 KB |
Output is correct |
92 |
Correct |
38 ms |
1220 KB |
Output is correct |
93 |
Correct |
35 ms |
1176 KB |
Output is correct |
94 |
Correct |
35 ms |
1100 KB |
Output is correct |
95 |
Correct |
39 ms |
1200 KB |
Output is correct |
96 |
Correct |
127 ms |
1120 KB |
Output is correct |
97 |
Correct |
672 ms |
1184 KB |
Output is correct |
98 |
Correct |
1010 ms |
1144 KB |
Output is correct |
99 |
Correct |
1123 ms |
1160 KB |
Output is correct |
100 |
Correct |
683 ms |
1220 KB |
Output is correct |