#include "train.h"
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef int ll;
#define MAX 6000
vector<ll> A, s;
ll N, M;
vector<ll> adj[MAX], rev[MAX], deg, d;
ll mp[MAX][MAX];
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
ll i;
A = a;
N = a.size();
M = u.size();
vector<ll> res, ans;
ans.resize(N);
for (i = 0; i < N; i++) if (r[i]) s.push_back(i);
for (i = 0; i < M; i++) adj[u[i]].push_back(v[i]), rev[v[i]].push_back(u[i]);
d.resize(N);
deg.resize(N);
res.resize(N);
ll T;
for (T = 1; T <= N; T++) {
bool chk = true;
for (i = 0; i < N; i++) {
res[i] = 0;
d[i] = 0;
deg[i] = 0;
if (ans[i]) continue;
for (auto x : adj[i]) {
if (ans[x]) continue;
d[i]++;
deg[i]++;
}
}
queue<ll> q;
for (auto st : s) {
if (ans[st]) continue;
q.push(st);
res[st] = 1;
}
ll j;
while (!q.empty()) {
ll t = q.front();
q.pop();
for (auto x : rev[t]) {
if (ans[x]) continue;
if (res[x]) continue;
deg[x]--;
if (a[x]) q.push(x), res[x] = 1;
else if (deg[x] <= 0) q.push(x), res[x] = 1;
}
}
//impossible
deg = d;
vector<ll> imp;
for (i = 0; i < N; i++) if (!res[i]) imp.push_back(i);
while (!q.empty()) q.pop();
for (auto st : imp) {
if (ans[st]) continue;
q.push(st);
ans[st] = 1;
chk = false;
}
while (!q.empty()) {
ll t = q.front();
q.pop();
for (auto x : rev[t]) {
if (ans[x]) continue;
deg[x]--;
if (!a[x]) q.push(x), ans[x] = 1, chk = false;
else if (deg[x] <= 0) q.push(x), ans[x] = 1, chk = false;
}
}
if (chk) break;
}
for (i = 0; i < N; i++) ans[i] = !ans[i];
return ans;
}
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:51:6: warning: unused variable 'j' [-Wunused-variable]
51 | ll j;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
1228 KB |
Output is correct |
2 |
Correct |
7 ms |
1228 KB |
Output is correct |
3 |
Correct |
8 ms |
1232 KB |
Output is correct |
4 |
Correct |
7 ms |
1228 KB |
Output is correct |
5 |
Correct |
6 ms |
1228 KB |
Output is correct |
6 |
Correct |
6 ms |
1228 KB |
Output is correct |
7 |
Correct |
7 ms |
1228 KB |
Output is correct |
8 |
Correct |
7 ms |
1100 KB |
Output is correct |
9 |
Correct |
6 ms |
1100 KB |
Output is correct |
10 |
Correct |
6 ms |
1172 KB |
Output is correct |
11 |
Correct |
5 ms |
1172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
588 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
588 KB |
Output is correct |
7 |
Correct |
1 ms |
588 KB |
Output is correct |
8 |
Correct |
1 ms |
588 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
588 KB |
Output is correct |
12 |
Correct |
1 ms |
588 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
1 ms |
588 KB |
Output is correct |
15 |
Correct |
1 ms |
588 KB |
Output is correct |
16 |
Correct |
1 ms |
588 KB |
Output is correct |
17 |
Correct |
1 ms |
588 KB |
Output is correct |
18 |
Correct |
1 ms |
460 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
168 ms |
1548 KB |
Output is correct |
2 |
Correct |
317 ms |
1528 KB |
Output is correct |
3 |
Correct |
439 ms |
1688 KB |
Output is correct |
4 |
Correct |
14 ms |
1484 KB |
Output is correct |
5 |
Correct |
11 ms |
1484 KB |
Output is correct |
6 |
Correct |
11 ms |
1560 KB |
Output is correct |
7 |
Correct |
10 ms |
1484 KB |
Output is correct |
8 |
Correct |
10 ms |
1484 KB |
Output is correct |
9 |
Correct |
9 ms |
1484 KB |
Output is correct |
10 |
Correct |
9 ms |
1464 KB |
Output is correct |
11 |
Correct |
9 ms |
1484 KB |
Output is correct |
12 |
Correct |
11 ms |
1356 KB |
Output is correct |
13 |
Correct |
10 ms |
1428 KB |
Output is correct |
14 |
Correct |
9 ms |
1484 KB |
Output is correct |
15 |
Correct |
10 ms |
1536 KB |
Output is correct |
16 |
Correct |
9 ms |
1484 KB |
Output is correct |
17 |
Correct |
10 ms |
1496 KB |
Output is correct |
18 |
Correct |
472 ms |
1268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1364 KB |
Output is correct |
2 |
Correct |
12 ms |
1300 KB |
Output is correct |
3 |
Correct |
10 ms |
1484 KB |
Output is correct |
4 |
Correct |
10 ms |
1512 KB |
Output is correct |
5 |
Correct |
11 ms |
1484 KB |
Output is correct |
6 |
Correct |
10 ms |
1484 KB |
Output is correct |
7 |
Correct |
10 ms |
1484 KB |
Output is correct |
8 |
Correct |
10 ms |
1484 KB |
Output is correct |
9 |
Correct |
11 ms |
1392 KB |
Output is correct |
10 |
Correct |
12 ms |
1432 KB |
Output is correct |
11 |
Correct |
12 ms |
1484 KB |
Output is correct |
12 |
Correct |
10 ms |
1516 KB |
Output is correct |
13 |
Correct |
10 ms |
1416 KB |
Output is correct |
14 |
Correct |
10 ms |
1356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
1416 KB |
Output is correct |
2 |
Correct |
10 ms |
1540 KB |
Output is correct |
3 |
Correct |
10 ms |
1612 KB |
Output is correct |
4 |
Correct |
9 ms |
1604 KB |
Output is correct |
5 |
Correct |
2 ms |
596 KB |
Output is correct |
6 |
Correct |
7 ms |
1228 KB |
Output is correct |
7 |
Correct |
8 ms |
1168 KB |
Output is correct |
8 |
Correct |
8 ms |
1356 KB |
Output is correct |
9 |
Correct |
6 ms |
1240 KB |
Output is correct |
10 |
Correct |
3 ms |
716 KB |
Output is correct |
11 |
Correct |
6 ms |
1228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
1228 KB |
Output is correct |
2 |
Correct |
7 ms |
1228 KB |
Output is correct |
3 |
Correct |
8 ms |
1232 KB |
Output is correct |
4 |
Correct |
7 ms |
1228 KB |
Output is correct |
5 |
Correct |
6 ms |
1228 KB |
Output is correct |
6 |
Correct |
6 ms |
1228 KB |
Output is correct |
7 |
Correct |
7 ms |
1228 KB |
Output is correct |
8 |
Correct |
7 ms |
1100 KB |
Output is correct |
9 |
Correct |
6 ms |
1100 KB |
Output is correct |
10 |
Correct |
6 ms |
1172 KB |
Output is correct |
11 |
Correct |
5 ms |
1172 KB |
Output is correct |
12 |
Correct |
1 ms |
588 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
1 ms |
588 KB |
Output is correct |
15 |
Correct |
1 ms |
588 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
588 KB |
Output is correct |
18 |
Correct |
1 ms |
588 KB |
Output is correct |
19 |
Correct |
1 ms |
588 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
21 |
Correct |
1 ms |
460 KB |
Output is correct |
22 |
Correct |
1 ms |
588 KB |
Output is correct |
23 |
Correct |
1 ms |
588 KB |
Output is correct |
24 |
Correct |
1 ms |
460 KB |
Output is correct |
25 |
Correct |
1 ms |
588 KB |
Output is correct |
26 |
Correct |
1 ms |
588 KB |
Output is correct |
27 |
Correct |
1 ms |
588 KB |
Output is correct |
28 |
Correct |
1 ms |
588 KB |
Output is correct |
29 |
Correct |
1 ms |
460 KB |
Output is correct |
30 |
Correct |
1 ms |
460 KB |
Output is correct |
31 |
Correct |
1 ms |
460 KB |
Output is correct |
32 |
Correct |
168 ms |
1548 KB |
Output is correct |
33 |
Correct |
317 ms |
1528 KB |
Output is correct |
34 |
Correct |
439 ms |
1688 KB |
Output is correct |
35 |
Correct |
14 ms |
1484 KB |
Output is correct |
36 |
Correct |
11 ms |
1484 KB |
Output is correct |
37 |
Correct |
11 ms |
1560 KB |
Output is correct |
38 |
Correct |
10 ms |
1484 KB |
Output is correct |
39 |
Correct |
10 ms |
1484 KB |
Output is correct |
40 |
Correct |
9 ms |
1484 KB |
Output is correct |
41 |
Correct |
9 ms |
1464 KB |
Output is correct |
42 |
Correct |
9 ms |
1484 KB |
Output is correct |
43 |
Correct |
11 ms |
1356 KB |
Output is correct |
44 |
Correct |
10 ms |
1428 KB |
Output is correct |
45 |
Correct |
9 ms |
1484 KB |
Output is correct |
46 |
Correct |
10 ms |
1536 KB |
Output is correct |
47 |
Correct |
9 ms |
1484 KB |
Output is correct |
48 |
Correct |
10 ms |
1496 KB |
Output is correct |
49 |
Correct |
472 ms |
1268 KB |
Output is correct |
50 |
Correct |
9 ms |
1364 KB |
Output is correct |
51 |
Correct |
12 ms |
1300 KB |
Output is correct |
52 |
Correct |
10 ms |
1484 KB |
Output is correct |
53 |
Correct |
10 ms |
1512 KB |
Output is correct |
54 |
Correct |
11 ms |
1484 KB |
Output is correct |
55 |
Correct |
10 ms |
1484 KB |
Output is correct |
56 |
Correct |
10 ms |
1484 KB |
Output is correct |
57 |
Correct |
10 ms |
1484 KB |
Output is correct |
58 |
Correct |
11 ms |
1392 KB |
Output is correct |
59 |
Correct |
12 ms |
1432 KB |
Output is correct |
60 |
Correct |
12 ms |
1484 KB |
Output is correct |
61 |
Correct |
10 ms |
1516 KB |
Output is correct |
62 |
Correct |
10 ms |
1416 KB |
Output is correct |
63 |
Correct |
10 ms |
1356 KB |
Output is correct |
64 |
Correct |
11 ms |
1416 KB |
Output is correct |
65 |
Correct |
10 ms |
1540 KB |
Output is correct |
66 |
Correct |
10 ms |
1612 KB |
Output is correct |
67 |
Correct |
9 ms |
1604 KB |
Output is correct |
68 |
Correct |
2 ms |
596 KB |
Output is correct |
69 |
Correct |
7 ms |
1228 KB |
Output is correct |
70 |
Correct |
8 ms |
1168 KB |
Output is correct |
71 |
Correct |
8 ms |
1356 KB |
Output is correct |
72 |
Correct |
6 ms |
1240 KB |
Output is correct |
73 |
Correct |
3 ms |
716 KB |
Output is correct |
74 |
Correct |
6 ms |
1228 KB |
Output is correct |
75 |
Correct |
270 ms |
1832 KB |
Output is correct |
76 |
Correct |
349 ms |
1748 KB |
Output is correct |
77 |
Correct |
488 ms |
1856 KB |
Output is correct |
78 |
Correct |
520 ms |
1744 KB |
Output is correct |
79 |
Correct |
481 ms |
1768 KB |
Output is correct |
80 |
Correct |
11 ms |
1612 KB |
Output is correct |
81 |
Correct |
11 ms |
1748 KB |
Output is correct |
82 |
Correct |
12 ms |
1612 KB |
Output is correct |
83 |
Correct |
11 ms |
1664 KB |
Output is correct |
84 |
Correct |
13 ms |
1616 KB |
Output is correct |
85 |
Correct |
11 ms |
1724 KB |
Output is correct |
86 |
Correct |
14 ms |
1740 KB |
Output is correct |
87 |
Correct |
10 ms |
1740 KB |
Output is correct |
88 |
Correct |
15 ms |
1744 KB |
Output is correct |
89 |
Correct |
11 ms |
1720 KB |
Output is correct |
90 |
Correct |
20 ms |
1736 KB |
Output is correct |
91 |
Correct |
18 ms |
1740 KB |
Output is correct |
92 |
Correct |
30 ms |
1736 KB |
Output is correct |
93 |
Correct |
33 ms |
1612 KB |
Output is correct |
94 |
Correct |
33 ms |
1720 KB |
Output is correct |
95 |
Correct |
33 ms |
1612 KB |
Output is correct |
96 |
Correct |
113 ms |
1592 KB |
Output is correct |
97 |
Correct |
439 ms |
1732 KB |
Output is correct |
98 |
Correct |
685 ms |
1684 KB |
Output is correct |
99 |
Correct |
695 ms |
1732 KB |
Output is correct |
100 |
Correct |
491 ms |
1496 KB |
Output is correct |