#include<bits/stdc++.h>
#include "train.h"
using namespace std;
const int nax = 5000;
int n, m;
vector<int>g[nax];
vector<int>A, R;
vector<int>cr(nax, -1);
vector<int>stk;
bool solve(int v) {
cr[v] = stk.size();
stk.push_back(v);
bool win = false;
for(int u : g[v]) {
if(cr[u]==-1) {
win |= solve(u) ^ (A[v]!=A[u]);
} else {
bool is = false;
for(int j=stk.size()-1; j>=cr[u]; --j) {
is |= R[stk[j]];
}
if(is && A[v]) win = true;
else if(!is && !A[v]) win = true;
}
}
cr[v] = -1;
stk.pop_back();
return win;
}
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
n = a.size(), m = u.size();
for(int i=0; i<m; ++i) {
g[u[i]].push_back(v[i]);
}
A = a, R = r;
vector<int>res(n);
for(int i=0; i<n; ++i) {
res[i] = solve(i) ^ (A[i]!=1);
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
293 ms |
1260 KB |
Output is correct |
2 |
Correct |
99 ms |
1124 KB |
Output is correct |
3 |
Correct |
45 ms |
980 KB |
Output is correct |
4 |
Correct |
16 ms |
964 KB |
Output is correct |
5 |
Correct |
10 ms |
852 KB |
Output is correct |
6 |
Correct |
5 ms |
832 KB |
Output is correct |
7 |
Correct |
5 ms |
852 KB |
Output is correct |
8 |
Correct |
4 ms |
852 KB |
Output is correct |
9 |
Correct |
4 ms |
852 KB |
Output is correct |
10 |
Correct |
3 ms |
840 KB |
Output is correct |
11 |
Correct |
5 ms |
836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
264 ms |
424 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
436 KB |
Output is correct |
8 |
Correct |
5 ms |
340 KB |
Output is correct |
9 |
Correct |
84 ms |
436 KB |
Output is correct |
10 |
Correct |
1 ms |
440 KB |
Output is correct |
11 |
Correct |
31 ms |
444 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
440 KB |
Output is correct |
17 |
Correct |
1 ms |
436 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2053 ms |
1020 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2073 ms |
1088 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2063 ms |
1328 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
293 ms |
1260 KB |
Output is correct |
2 |
Correct |
99 ms |
1124 KB |
Output is correct |
3 |
Correct |
45 ms |
980 KB |
Output is correct |
4 |
Correct |
16 ms |
964 KB |
Output is correct |
5 |
Correct |
10 ms |
852 KB |
Output is correct |
6 |
Correct |
5 ms |
832 KB |
Output is correct |
7 |
Correct |
5 ms |
852 KB |
Output is correct |
8 |
Correct |
4 ms |
852 KB |
Output is correct |
9 |
Correct |
4 ms |
852 KB |
Output is correct |
10 |
Correct |
3 ms |
840 KB |
Output is correct |
11 |
Correct |
5 ms |
836 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
264 ms |
424 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
436 KB |
Output is correct |
19 |
Correct |
5 ms |
340 KB |
Output is correct |
20 |
Correct |
84 ms |
436 KB |
Output is correct |
21 |
Correct |
1 ms |
440 KB |
Output is correct |
22 |
Correct |
31 ms |
444 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
440 KB |
Output is correct |
28 |
Correct |
1 ms |
436 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
444 KB |
Output is correct |
32 |
Execution timed out |
2053 ms |
1020 KB |
Time limit exceeded |
33 |
Halted |
0 ms |
0 KB |
- |