#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> 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]);
}
vector<int>nontrap(n), trap(n), need(n);
int tt = n;
while(tt--) {
queue<int>q;
for(int i=0; i<n; ++i) {
need[i] = trap[i] = nontrap[i] = 0;
}
for(int i=0; i<n; ++i) {
if(R[i]) nontrap[i] = 1, q.push(i);
else trap[i] = 1;
}
for(int i=0; i<n; ++i) {
if(nontrap[i]) continue;
if(A[i]) need[i] = 1;
else need[i] = g[i].size();
}
while(!q.empty()) {
int v = q.front(); q.pop();
trap[v] = 0, nontrap[v] = 1;
for(int to : gt[v]) {
if(--need[to]==0) {
q.push(to);
}
}
}
for(int x=0; x<n; ++x) if(nontrap[x]) {
bool all = true, one = false;
for(int to : g[x]) {
all &= trap[to];
one |= trap[to];
}
if((A[x] && all) || (!A[x] && one)) {
nontrap[x] = 0, trap[x] = 1, R[x] = 0;
}
}
}
return nontrap;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
665 ms |
1172 KB |
Output is correct |
2 |
Correct |
635 ms |
1176 KB |
Output is correct |
3 |
Correct |
663 ms |
1160 KB |
Output is correct |
4 |
Correct |
623 ms |
1168 KB |
Output is correct |
5 |
Correct |
642 ms |
1164 KB |
Output is correct |
6 |
Correct |
690 ms |
1160 KB |
Output is correct |
7 |
Correct |
287 ms |
1164 KB |
Output is correct |
8 |
Correct |
909 ms |
1160 KB |
Output is correct |
9 |
Correct |
722 ms |
1192 KB |
Output is correct |
10 |
Correct |
691 ms |
1124 KB |
Output is correct |
11 |
Correct |
609 ms |
1128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
540 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
536 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
536 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 |
536 KB |
Output is correct |
17 |
Correct |
1 ms |
540 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
228 ms |
1572 KB |
Output is correct |
2 |
Correct |
300 ms |
1568 KB |
Output is correct |
3 |
Correct |
351 ms |
1560 KB |
Output is correct |
4 |
Correct |
1414 ms |
1524 KB |
Output is correct |
5 |
Correct |
1056 ms |
1520 KB |
Output is correct |
6 |
Correct |
187 ms |
1512 KB |
Output is correct |
7 |
Correct |
1524 ms |
1520 KB |
Output is correct |
8 |
Correct |
740 ms |
1508 KB |
Output is correct |
9 |
Correct |
170 ms |
1488 KB |
Output is correct |
10 |
Correct |
1099 ms |
1492 KB |
Output is correct |
11 |
Correct |
856 ms |
1456 KB |
Output is correct |
12 |
Correct |
163 ms |
1484 KB |
Output is correct |
13 |
Correct |
1451 ms |
1520 KB |
Output is correct |
14 |
Correct |
1485 ms |
1524 KB |
Output is correct |
15 |
Correct |
1464 ms |
1528 KB |
Output is correct |
16 |
Correct |
1453 ms |
1524 KB |
Output is correct |
17 |
Correct |
1426 ms |
1528 KB |
Output is correct |
18 |
Correct |
411 ms |
1248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1055 ms |
1376 KB |
Output is correct |
2 |
Correct |
1119 ms |
1484 KB |
Output is correct |
3 |
Correct |
205 ms |
1388 KB |
Output is correct |
4 |
Correct |
154 ms |
1512 KB |
Output is correct |
5 |
Correct |
815 ms |
1508 KB |
Output is correct |
6 |
Correct |
1186 ms |
1612 KB |
Output is correct |
7 |
Correct |
1084 ms |
1504 KB |
Output is correct |
8 |
Correct |
177 ms |
1372 KB |
Output is correct |
9 |
Correct |
950 ms |
1452 KB |
Output is correct |
10 |
Correct |
1337 ms |
1532 KB |
Output is correct |
11 |
Correct |
1231 ms |
1536 KB |
Output is correct |
12 |
Correct |
1341 ms |
1576 KB |
Output is correct |
13 |
Correct |
906 ms |
1512 KB |
Output is correct |
14 |
Correct |
1117 ms |
1440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1031 ms |
1512 KB |
Output is correct |
2 |
Correct |
1620 ms |
1520 KB |
Output is correct |
3 |
Correct |
1421 ms |
1512 KB |
Output is correct |
4 |
Correct |
1636 ms |
1432 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
189 ms |
1112 KB |
Output is correct |
7 |
Correct |
38 ms |
1108 KB |
Output is correct |
8 |
Correct |
6 ms |
1236 KB |
Output is correct |
9 |
Correct |
32 ms |
1236 KB |
Output is correct |
10 |
Correct |
3 ms |
724 KB |
Output is correct |
11 |
Correct |
69 ms |
1108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
665 ms |
1172 KB |
Output is correct |
2 |
Correct |
635 ms |
1176 KB |
Output is correct |
3 |
Correct |
663 ms |
1160 KB |
Output is correct |
4 |
Correct |
623 ms |
1168 KB |
Output is correct |
5 |
Correct |
642 ms |
1164 KB |
Output is correct |
6 |
Correct |
690 ms |
1160 KB |
Output is correct |
7 |
Correct |
287 ms |
1164 KB |
Output is correct |
8 |
Correct |
909 ms |
1160 KB |
Output is correct |
9 |
Correct |
722 ms |
1192 KB |
Output is correct |
10 |
Correct |
691 ms |
1124 KB |
Output is correct |
11 |
Correct |
609 ms |
1128 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 |
540 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 |
1 ms |
536 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
536 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 |
536 KB |
Output is correct |
28 |
Correct |
1 ms |
540 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
536 KB |
Output is correct |
32 |
Correct |
228 ms |
1572 KB |
Output is correct |
33 |
Correct |
300 ms |
1568 KB |
Output is correct |
34 |
Correct |
351 ms |
1560 KB |
Output is correct |
35 |
Correct |
1414 ms |
1524 KB |
Output is correct |
36 |
Correct |
1056 ms |
1520 KB |
Output is correct |
37 |
Correct |
187 ms |
1512 KB |
Output is correct |
38 |
Correct |
1524 ms |
1520 KB |
Output is correct |
39 |
Correct |
740 ms |
1508 KB |
Output is correct |
40 |
Correct |
170 ms |
1488 KB |
Output is correct |
41 |
Correct |
1099 ms |
1492 KB |
Output is correct |
42 |
Correct |
856 ms |
1456 KB |
Output is correct |
43 |
Correct |
163 ms |
1484 KB |
Output is correct |
44 |
Correct |
1451 ms |
1520 KB |
Output is correct |
45 |
Correct |
1485 ms |
1524 KB |
Output is correct |
46 |
Correct |
1464 ms |
1528 KB |
Output is correct |
47 |
Correct |
1453 ms |
1524 KB |
Output is correct |
48 |
Correct |
1426 ms |
1528 KB |
Output is correct |
49 |
Correct |
411 ms |
1248 KB |
Output is correct |
50 |
Correct |
1055 ms |
1376 KB |
Output is correct |
51 |
Correct |
1119 ms |
1484 KB |
Output is correct |
52 |
Correct |
205 ms |
1388 KB |
Output is correct |
53 |
Correct |
154 ms |
1512 KB |
Output is correct |
54 |
Correct |
815 ms |
1508 KB |
Output is correct |
55 |
Correct |
1186 ms |
1612 KB |
Output is correct |
56 |
Correct |
1084 ms |
1504 KB |
Output is correct |
57 |
Correct |
177 ms |
1372 KB |
Output is correct |
58 |
Correct |
950 ms |
1452 KB |
Output is correct |
59 |
Correct |
1337 ms |
1532 KB |
Output is correct |
60 |
Correct |
1231 ms |
1536 KB |
Output is correct |
61 |
Correct |
1341 ms |
1576 KB |
Output is correct |
62 |
Correct |
906 ms |
1512 KB |
Output is correct |
63 |
Correct |
1117 ms |
1440 KB |
Output is correct |
64 |
Correct |
1031 ms |
1512 KB |
Output is correct |
65 |
Correct |
1620 ms |
1520 KB |
Output is correct |
66 |
Correct |
1421 ms |
1512 KB |
Output is correct |
67 |
Correct |
1636 ms |
1432 KB |
Output is correct |
68 |
Correct |
1 ms |
596 KB |
Output is correct |
69 |
Correct |
189 ms |
1112 KB |
Output is correct |
70 |
Correct |
38 ms |
1108 KB |
Output is correct |
71 |
Correct |
6 ms |
1236 KB |
Output is correct |
72 |
Correct |
32 ms |
1236 KB |
Output is correct |
73 |
Correct |
3 ms |
724 KB |
Output is correct |
74 |
Correct |
69 ms |
1108 KB |
Output is correct |
75 |
Correct |
257 ms |
1620 KB |
Output is correct |
76 |
Correct |
323 ms |
1656 KB |
Output is correct |
77 |
Correct |
387 ms |
1648 KB |
Output is correct |
78 |
Correct |
416 ms |
1636 KB |
Output is correct |
79 |
Correct |
387 ms |
1640 KB |
Output is correct |
80 |
Correct |
1642 ms |
1600 KB |
Output is correct |
81 |
Correct |
665 ms |
1596 KB |
Output is correct |
82 |
Correct |
1000 ms |
1588 KB |
Output is correct |
83 |
Correct |
1119 ms |
1600 KB |
Output is correct |
84 |
Correct |
861 ms |
1596 KB |
Output is correct |
85 |
Correct |
180 ms |
1580 KB |
Output is correct |
86 |
Correct |
692 ms |
1600 KB |
Output is correct |
87 |
Correct |
163 ms |
1588 KB |
Output is correct |
88 |
Correct |
422 ms |
1588 KB |
Output is correct |
89 |
Correct |
739 ms |
1588 KB |
Output is correct |
90 |
Correct |
182 ms |
1596 KB |
Output is correct |
91 |
Correct |
290 ms |
1596 KB |
Output is correct |
92 |
Correct |
729 ms |
1596 KB |
Output is correct |
93 |
Correct |
551 ms |
1584 KB |
Output is correct |
94 |
Correct |
427 ms |
1612 KB |
Output is correct |
95 |
Correct |
697 ms |
1612 KB |
Output is correct |
96 |
Correct |
1185 ms |
1508 KB |
Output is correct |
97 |
Correct |
486 ms |
1604 KB |
Output is correct |
98 |
Correct |
594 ms |
1576 KB |
Output is correct |
99 |
Correct |
513 ms |
1560 KB |
Output is correct |
100 |
Correct |
372 ms |
1236 KB |
Output is correct |