#include "train.h"
#include <vector>
using namespace std;
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#include <algorithm>
#define x first
#define y second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vb vector<bool>
int n, m;
const int siz = 5e3 + 1;
vi fr[siz];
vi invf[siz];
#include <queue>
int a[siz];
int deg[siz];
void func(vi& bad) {
vector<bool> vis(n);
queue<int> q;
for (int i = 0; i < n; i++)if (bad[i])q.push(i);
for (int i = 0; i < n; i++)deg[i] = fr[i].size();
while (!q.empty()) {
int i = q.front();
q.pop();
if (vis[i])continue;
vis[i] = 1;
bad[i] = 1;
for (int f : invf[i]) {
if (vis[f])continue;
deg[f]--;
if (a[f] == 1) {
if (deg[f] == fr[f].size() - 1)q.push(f);
}
else {
if (deg[f] == 0)q.push(f);
}
}
}
}
vi who_wins(vi A, vi R, vi U, vi V) {
n = R.size(), m = U.size();
for (int i = 0; i < n; i++)a[i] = A[i];
for (int i = 0; i < m; i++) {
fr[U[i]].push_back(V[i]);
invf[V[i]].push_back(U[i]);
}
vi bad(n,1);
for (int it = 0; it <= n; it++) {
vi badt(n);
for (int i = 0; i < n; i++) {
//if (bad[i]) {
if (A[i]) {
bool g = 0;
for (int j : fr[i])if (bad[j])g = 1;
if (g == 0)badt[i] = 0;
else badt[i] = 1;
}
else {
for (int j : fr[i]) {
if (bad[j] == 0) {
badt[i] = 0;
break;
}
if (j == fr[i].back())badt[i] = 1;
}
}
//}
}
bad = badt;
vi badtt = R; for (int i = 0; i < n; i++)if (bad[i] == 0)badtt[i] = 0;
func(badtt);
for (int i = 0; i < n; i++)if (badtt[i] == 0)bad[i] = 0;
}
return bad;
}
Compilation message
train.cpp: In function 'void func(std::vector<int>&)':
train.cpp:35:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | if (deg[f] == fr[f].size() - 1)q.push(f);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
669 ms |
1236 KB |
Output is correct |
2 |
Correct |
628 ms |
1116 KB |
Output is correct |
3 |
Correct |
635 ms |
1232 KB |
Output is correct |
4 |
Correct |
620 ms |
1244 KB |
Output is correct |
5 |
Correct |
615 ms |
1364 KB |
Output is correct |
6 |
Correct |
630 ms |
1232 KB |
Output is correct |
7 |
Correct |
262 ms |
1240 KB |
Output is correct |
8 |
Correct |
686 ms |
1116 KB |
Output is correct |
9 |
Correct |
692 ms |
1360 KB |
Output is correct |
10 |
Correct |
727 ms |
1200 KB |
Output is correct |
11 |
Correct |
701 ms |
1220 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
604 KB |
Output is correct |
12 |
Correct |
0 ms |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
600 KB |
Output is correct |
16 |
Correct |
0 ms |
600 KB |
Output is correct |
17 |
Correct |
0 ms |
604 KB |
Output is correct |
18 |
Correct |
0 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
0 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
313 ms |
1604 KB |
Output is correct |
2 |
Correct |
360 ms |
1372 KB |
Output is correct |
3 |
Correct |
403 ms |
1372 KB |
Output is correct |
4 |
Correct |
1304 ms |
1372 KB |
Output is correct |
5 |
Correct |
1192 ms |
1628 KB |
Output is correct |
6 |
Correct |
411 ms |
1368 KB |
Output is correct |
7 |
Correct |
1539 ms |
1548 KB |
Output is correct |
8 |
Correct |
952 ms |
1532 KB |
Output is correct |
9 |
Correct |
324 ms |
1512 KB |
Output is correct |
10 |
Correct |
1100 ms |
1504 KB |
Output is correct |
11 |
Correct |
1057 ms |
1620 KB |
Output is correct |
12 |
Correct |
366 ms |
1624 KB |
Output is correct |
13 |
Correct |
1459 ms |
1548 KB |
Output is correct |
14 |
Correct |
1516 ms |
1560 KB |
Output is correct |
15 |
Correct |
1562 ms |
1564 KB |
Output is correct |
16 |
Correct |
1471 ms |
1372 KB |
Output is correct |
17 |
Correct |
1455 ms |
1552 KB |
Output is correct |
18 |
Correct |
399 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1262 ms |
1396 KB |
Output is correct |
2 |
Correct |
1285 ms |
1620 KB |
Output is correct |
3 |
Correct |
256 ms |
1620 KB |
Output is correct |
4 |
Correct |
189 ms |
1368 KB |
Output is correct |
5 |
Correct |
1168 ms |
1620 KB |
Output is correct |
6 |
Correct |
1413 ms |
1528 KB |
Output is correct |
7 |
Correct |
1376 ms |
1520 KB |
Output is correct |
8 |
Correct |
227 ms |
1496 KB |
Output is correct |
9 |
Correct |
1348 ms |
1480 KB |
Output is correct |
10 |
Correct |
1498 ms |
1616 KB |
Output is correct |
11 |
Correct |
1441 ms |
1564 KB |
Output is correct |
12 |
Correct |
1522 ms |
1560 KB |
Output is correct |
13 |
Correct |
1268 ms |
1532 KB |
Output is correct |
14 |
Correct |
1326 ms |
1584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1315 ms |
1544 KB |
Output is correct |
2 |
Correct |
1630 ms |
1548 KB |
Output is correct |
3 |
Correct |
1653 ms |
1540 KB |
Output is correct |
4 |
Correct |
1634 ms |
1460 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
208 ms |
1116 KB |
Output is correct |
7 |
Correct |
37 ms |
1116 KB |
Output is correct |
8 |
Correct |
9 ms |
1116 KB |
Output is correct |
9 |
Correct |
31 ms |
1116 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
80 ms |
1176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
669 ms |
1236 KB |
Output is correct |
2 |
Correct |
628 ms |
1116 KB |
Output is correct |
3 |
Correct |
635 ms |
1232 KB |
Output is correct |
4 |
Correct |
620 ms |
1244 KB |
Output is correct |
5 |
Correct |
615 ms |
1364 KB |
Output is correct |
6 |
Correct |
630 ms |
1232 KB |
Output is correct |
7 |
Correct |
262 ms |
1240 KB |
Output is correct |
8 |
Correct |
686 ms |
1116 KB |
Output is correct |
9 |
Correct |
692 ms |
1360 KB |
Output is correct |
10 |
Correct |
727 ms |
1200 KB |
Output is correct |
11 |
Correct |
701 ms |
1220 KB |
Output is correct |
12 |
Correct |
0 ms |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
16 |
Correct |
0 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
0 ms |
604 KB |
Output is correct |
20 |
Correct |
0 ms |
604 KB |
Output is correct |
21 |
Correct |
0 ms |
604 KB |
Output is correct |
22 |
Correct |
0 ms |
604 KB |
Output is correct |
23 |
Correct |
0 ms |
604 KB |
Output is correct |
24 |
Correct |
0 ms |
604 KB |
Output is correct |
25 |
Correct |
0 ms |
604 KB |
Output is correct |
26 |
Correct |
0 ms |
600 KB |
Output is correct |
27 |
Correct |
0 ms |
600 KB |
Output is correct |
28 |
Correct |
0 ms |
604 KB |
Output is correct |
29 |
Correct |
0 ms |
604 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
0 ms |
604 KB |
Output is correct |
32 |
Correct |
313 ms |
1604 KB |
Output is correct |
33 |
Correct |
360 ms |
1372 KB |
Output is correct |
34 |
Correct |
403 ms |
1372 KB |
Output is correct |
35 |
Correct |
1304 ms |
1372 KB |
Output is correct |
36 |
Correct |
1192 ms |
1628 KB |
Output is correct |
37 |
Correct |
411 ms |
1368 KB |
Output is correct |
38 |
Correct |
1539 ms |
1548 KB |
Output is correct |
39 |
Correct |
952 ms |
1532 KB |
Output is correct |
40 |
Correct |
324 ms |
1512 KB |
Output is correct |
41 |
Correct |
1100 ms |
1504 KB |
Output is correct |
42 |
Correct |
1057 ms |
1620 KB |
Output is correct |
43 |
Correct |
366 ms |
1624 KB |
Output is correct |
44 |
Correct |
1459 ms |
1548 KB |
Output is correct |
45 |
Correct |
1516 ms |
1560 KB |
Output is correct |
46 |
Correct |
1562 ms |
1564 KB |
Output is correct |
47 |
Correct |
1471 ms |
1372 KB |
Output is correct |
48 |
Correct |
1455 ms |
1552 KB |
Output is correct |
49 |
Correct |
399 ms |
1116 KB |
Output is correct |
50 |
Correct |
1262 ms |
1396 KB |
Output is correct |
51 |
Correct |
1285 ms |
1620 KB |
Output is correct |
52 |
Correct |
256 ms |
1620 KB |
Output is correct |
53 |
Correct |
189 ms |
1368 KB |
Output is correct |
54 |
Correct |
1168 ms |
1620 KB |
Output is correct |
55 |
Correct |
1413 ms |
1528 KB |
Output is correct |
56 |
Correct |
1376 ms |
1520 KB |
Output is correct |
57 |
Correct |
227 ms |
1496 KB |
Output is correct |
58 |
Correct |
1348 ms |
1480 KB |
Output is correct |
59 |
Correct |
1498 ms |
1616 KB |
Output is correct |
60 |
Correct |
1441 ms |
1564 KB |
Output is correct |
61 |
Correct |
1522 ms |
1560 KB |
Output is correct |
62 |
Correct |
1268 ms |
1532 KB |
Output is correct |
63 |
Correct |
1326 ms |
1584 KB |
Output is correct |
64 |
Correct |
1315 ms |
1544 KB |
Output is correct |
65 |
Correct |
1630 ms |
1548 KB |
Output is correct |
66 |
Correct |
1653 ms |
1540 KB |
Output is correct |
67 |
Correct |
1634 ms |
1460 KB |
Output is correct |
68 |
Correct |
1 ms |
604 KB |
Output is correct |
69 |
Correct |
208 ms |
1116 KB |
Output is correct |
70 |
Correct |
37 ms |
1116 KB |
Output is correct |
71 |
Correct |
9 ms |
1116 KB |
Output is correct |
72 |
Correct |
31 ms |
1116 KB |
Output is correct |
73 |
Correct |
2 ms |
604 KB |
Output is correct |
74 |
Correct |
80 ms |
1176 KB |
Output is correct |
75 |
Correct |
237 ms |
1372 KB |
Output is correct |
76 |
Correct |
355 ms |
1604 KB |
Output is correct |
77 |
Correct |
397 ms |
1368 KB |
Output is correct |
78 |
Correct |
422 ms |
1620 KB |
Output is correct |
79 |
Correct |
406 ms |
1372 KB |
Output is correct |
80 |
Correct |
1703 ms |
1556 KB |
Output is correct |
81 |
Correct |
930 ms |
1540 KB |
Output is correct |
82 |
Correct |
1371 ms |
1532 KB |
Output is correct |
83 |
Correct |
1270 ms |
1552 KB |
Output is correct |
84 |
Correct |
1192 ms |
1548 KB |
Output is correct |
85 |
Correct |
212 ms |
1368 KB |
Output is correct |
86 |
Correct |
1037 ms |
1548 KB |
Output is correct |
87 |
Correct |
201 ms |
1372 KB |
Output is correct |
88 |
Correct |
670 ms |
1556 KB |
Output is correct |
89 |
Correct |
1114 ms |
1540 KB |
Output is correct |
90 |
Correct |
328 ms |
1624 KB |
Output is correct |
91 |
Correct |
509 ms |
1544 KB |
Output is correct |
92 |
Correct |
1085 ms |
1560 KB |
Output is correct |
93 |
Correct |
832 ms |
1532 KB |
Output is correct |
94 |
Correct |
669 ms |
1544 KB |
Output is correct |
95 |
Correct |
1095 ms |
1552 KB |
Output is correct |
96 |
Correct |
1350 ms |
1492 KB |
Output is correct |
97 |
Correct |
653 ms |
1552 KB |
Output is correct |
98 |
Correct |
833 ms |
1540 KB |
Output is correct |
99 |
Correct |
666 ms |
1520 KB |
Output is correct |
100 |
Correct |
383 ms |
1296 KB |
Output is correct |