#include<bits/stdc++.h>
#include "train.h"
using namespace std;
const int nax = 5000;
int n, m;
vector<int>g[nax], gt[nax];
vector<int>A, R;
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]);
gt[v[i]].push_back(u[i]);
}
A = a, R = r;
vector<int>res(n);
while(1) {
set<int>nontrap, trap;
queue<int>q;
for(int i=0; i<n; ++i) {
if(R[i]) nontrap.insert(i), q.push(i);
else trap.insert(i);
}
int need[n] = {0};
for(int i=0; i<n; ++i) {
if(nontrap.count(i)) continue;
if(A[i]) need[i] = 1;
else need[i] = g[i].size();
}
while(!q.empty()) {
int v = q.front(); q.pop();
trap.erase(v);
nontrap.insert(v);
for(int to : gt[v]) {
if(--need[to]==0) {
q.push(to);
}
}
}
vector<int>trans;
for(int x : nontrap) {
bool all = true, one = false;
for(int to : g[x]) {
all &= trap.count(to);
one |= trap.count(to);
}
if(A[x] && all) {
trans.push_back(x);
} else if(!A[x] && one) {
trans.push_back(x);
}
}
if(trans.empty()) {
for(int x : nontrap) res[x] = 1;
break;
}
for(int x : trans) {
trap.insert(x);
nontrap.erase(x);
R[x] = 0;
}
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
1364 KB |
Output is correct |
2 |
Correct |
30 ms |
1236 KB |
Output is correct |
3 |
Correct |
26 ms |
1360 KB |
Output is correct |
4 |
Correct |
38 ms |
1336 KB |
Output is correct |
5 |
Correct |
26 ms |
1356 KB |
Output is correct |
6 |
Correct |
30 ms |
1236 KB |
Output is correct |
7 |
Correct |
22 ms |
1364 KB |
Output is correct |
8 |
Correct |
24 ms |
1340 KB |
Output is correct |
9 |
Correct |
16 ms |
1336 KB |
Output is correct |
10 |
Correct |
10 ms |
1236 KB |
Output is correct |
11 |
Correct |
4 ms |
1236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
0 ms |
468 KB |
Output is correct |
8 |
Correct |
0 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
0 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
0 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1400 ms |
1696 KB |
Output is correct |
2 |
Execution timed out |
2075 ms |
1876 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
1492 KB |
Output is correct |
2 |
Correct |
13 ms |
1560 KB |
Output is correct |
3 |
Correct |
10 ms |
1624 KB |
Output is correct |
4 |
Correct |
16 ms |
1672 KB |
Output is correct |
5 |
Correct |
16 ms |
1876 KB |
Output is correct |
6 |
Correct |
17 ms |
1748 KB |
Output is correct |
7 |
Correct |
16 ms |
1748 KB |
Output is correct |
8 |
Correct |
11 ms |
1748 KB |
Output is correct |
9 |
Correct |
23 ms |
1748 KB |
Output is correct |
10 |
Correct |
9 ms |
1876 KB |
Output is correct |
11 |
Correct |
8 ms |
1836 KB |
Output is correct |
12 |
Correct |
9 ms |
1836 KB |
Output is correct |
13 |
Correct |
9 ms |
1812 KB |
Output is correct |
14 |
Correct |
10 ms |
1748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
1620 KB |
Output is correct |
2 |
Correct |
13 ms |
1664 KB |
Output is correct |
3 |
Correct |
10 ms |
1620 KB |
Output is correct |
4 |
Correct |
8 ms |
1492 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
5 ms |
1236 KB |
Output is correct |
7 |
Correct |
5 ms |
980 KB |
Output is correct |
8 |
Correct |
6 ms |
1072 KB |
Output is correct |
9 |
Correct |
7 ms |
1108 KB |
Output is correct |
10 |
Correct |
2 ms |
724 KB |
Output is correct |
11 |
Correct |
5 ms |
980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
1364 KB |
Output is correct |
2 |
Correct |
30 ms |
1236 KB |
Output is correct |
3 |
Correct |
26 ms |
1360 KB |
Output is correct |
4 |
Correct |
38 ms |
1336 KB |
Output is correct |
5 |
Correct |
26 ms |
1356 KB |
Output is correct |
6 |
Correct |
30 ms |
1236 KB |
Output is correct |
7 |
Correct |
22 ms |
1364 KB |
Output is correct |
8 |
Correct |
24 ms |
1340 KB |
Output is correct |
9 |
Correct |
16 ms |
1336 KB |
Output is correct |
10 |
Correct |
10 ms |
1236 KB |
Output is correct |
11 |
Correct |
4 ms |
1236 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
0 ms |
468 KB |
Output is correct |
19 |
Correct |
0 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
0 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
0 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
1400 ms |
1696 KB |
Output is correct |
33 |
Execution timed out |
2075 ms |
1876 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |