#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]);
ll T;
for (T = 1; T <= N; T++) {
d.clear();
d.resize(N);
res.clear();
res.resize(N);
for (i = 0; i < N; i++) {
if (ans[i]) continue;
for (auto x : adj[i]) {
if (ans[x]) continue;
d[i]++;
}
}
deg = d;
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;
}
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;
else if (deg[x] <= 0) q.push(x), ans[x] = 1;
}
}
}
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:48:6: warning: unused variable 'j' [-Wunused-variable]
48 | ll j;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
622 ms |
1208 KB |
Output is correct |
2 |
Correct |
617 ms |
1204 KB |
Output is correct |
3 |
Correct |
609 ms |
1200 KB |
Output is correct |
4 |
Correct |
572 ms |
1196 KB |
Output is correct |
5 |
Correct |
587 ms |
1228 KB |
Output is correct |
6 |
Correct |
666 ms |
1208 KB |
Output is correct |
7 |
Correct |
278 ms |
1228 KB |
Output is correct |
8 |
Correct |
909 ms |
1180 KB |
Output is correct |
9 |
Correct |
657 ms |
1176 KB |
Output is correct |
10 |
Correct |
632 ms |
1176 KB |
Output is correct |
11 |
Correct |
474 ms |
1220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
1 ms |
588 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 |
564 KB |
Output is correct |
10 |
Correct |
1 ms |
588 KB |
Output is correct |
11 |
Correct |
1 ms |
588 KB |
Output is correct |
12 |
Correct |
1 ms |
584 KB |
Output is correct |
13 |
Correct |
1 ms |
588 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 |
584 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 |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
250 ms |
1484 KB |
Output is correct |
2 |
Correct |
338 ms |
1620 KB |
Output is correct |
3 |
Correct |
452 ms |
1564 KB |
Output is correct |
4 |
Correct |
1793 ms |
1484 KB |
Output is correct |
5 |
Correct |
1611 ms |
1496 KB |
Output is correct |
6 |
Correct |
252 ms |
1544 KB |
Output is correct |
7 |
Correct |
1600 ms |
1688 KB |
Output is correct |
8 |
Correct |
1128 ms |
1700 KB |
Output is correct |
9 |
Correct |
168 ms |
1612 KB |
Output is correct |
10 |
Correct |
1592 ms |
1644 KB |
Output is correct |
11 |
Correct |
1311 ms |
1652 KB |
Output is correct |
12 |
Correct |
163 ms |
1732 KB |
Output is correct |
13 |
Correct |
1767 ms |
1696 KB |
Output is correct |
14 |
Correct |
1850 ms |
1712 KB |
Output is correct |
15 |
Correct |
1697 ms |
1704 KB |
Output is correct |
16 |
Correct |
1737 ms |
1692 KB |
Output is correct |
17 |
Correct |
1736 ms |
1692 KB |
Output is correct |
18 |
Correct |
433 ms |
1380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1285 ms |
1356 KB |
Output is correct |
2 |
Correct |
1759 ms |
1384 KB |
Output is correct |
3 |
Correct |
207 ms |
1484 KB |
Output is correct |
4 |
Correct |
168 ms |
1532 KB |
Output is correct |
5 |
Correct |
1349 ms |
1504 KB |
Output is correct |
6 |
Execution timed out |
2082 ms |
1484 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1845 ms |
1508 KB |
Output is correct |
2 |
Execution timed out |
2071 ms |
1612 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
622 ms |
1208 KB |
Output is correct |
2 |
Correct |
617 ms |
1204 KB |
Output is correct |
3 |
Correct |
609 ms |
1200 KB |
Output is correct |
4 |
Correct |
572 ms |
1196 KB |
Output is correct |
5 |
Correct |
587 ms |
1228 KB |
Output is correct |
6 |
Correct |
666 ms |
1208 KB |
Output is correct |
7 |
Correct |
278 ms |
1228 KB |
Output is correct |
8 |
Correct |
909 ms |
1180 KB |
Output is correct |
9 |
Correct |
657 ms |
1176 KB |
Output is correct |
10 |
Correct |
632 ms |
1176 KB |
Output is correct |
11 |
Correct |
474 ms |
1220 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
1 ms |
460 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 |
588 KB |
Output is correct |
19 |
Correct |
1 ms |
588 KB |
Output is correct |
20 |
Correct |
1 ms |
564 KB |
Output is correct |
21 |
Correct |
1 ms |
588 KB |
Output is correct |
22 |
Correct |
1 ms |
588 KB |
Output is correct |
23 |
Correct |
1 ms |
584 KB |
Output is correct |
24 |
Correct |
1 ms |
588 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 |
584 KB |
Output is correct |
28 |
Correct |
1 ms |
588 KB |
Output is correct |
29 |
Correct |
1 ms |
588 KB |
Output is correct |
30 |
Correct |
1 ms |
588 KB |
Output is correct |
31 |
Correct |
1 ms |
588 KB |
Output is correct |
32 |
Correct |
250 ms |
1484 KB |
Output is correct |
33 |
Correct |
338 ms |
1620 KB |
Output is correct |
34 |
Correct |
452 ms |
1564 KB |
Output is correct |
35 |
Correct |
1793 ms |
1484 KB |
Output is correct |
36 |
Correct |
1611 ms |
1496 KB |
Output is correct |
37 |
Correct |
252 ms |
1544 KB |
Output is correct |
38 |
Correct |
1600 ms |
1688 KB |
Output is correct |
39 |
Correct |
1128 ms |
1700 KB |
Output is correct |
40 |
Correct |
168 ms |
1612 KB |
Output is correct |
41 |
Correct |
1592 ms |
1644 KB |
Output is correct |
42 |
Correct |
1311 ms |
1652 KB |
Output is correct |
43 |
Correct |
163 ms |
1732 KB |
Output is correct |
44 |
Correct |
1767 ms |
1696 KB |
Output is correct |
45 |
Correct |
1850 ms |
1712 KB |
Output is correct |
46 |
Correct |
1697 ms |
1704 KB |
Output is correct |
47 |
Correct |
1737 ms |
1692 KB |
Output is correct |
48 |
Correct |
1736 ms |
1692 KB |
Output is correct |
49 |
Correct |
433 ms |
1380 KB |
Output is correct |
50 |
Correct |
1285 ms |
1356 KB |
Output is correct |
51 |
Correct |
1759 ms |
1384 KB |
Output is correct |
52 |
Correct |
207 ms |
1484 KB |
Output is correct |
53 |
Correct |
168 ms |
1532 KB |
Output is correct |
54 |
Correct |
1349 ms |
1504 KB |
Output is correct |
55 |
Execution timed out |
2082 ms |
1484 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |