#include "train.h"
#include <bits/stdc++.h>
using namespace std;
//macros
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define INF 1e9
#define pb push_back
#define fi first
#define se second
#define sz size()
const int MX=6000;
int n, m;
vi a, r, u, v;
vi res;
set<int> adj[MX], rev[MX];
int cnt[MX];
vi R;
bitset<MX> visited;
vi f(bool A, vi x) { // O(n+m)
vi ret;
queue<int> q;
RE(u,n) cnt[u] = 0;
visited.reset();
for(int u : x) q.push(u), visited[u] = 1;
while(!q.empty()) {
int u = q.front(); q.pop();
ret.push_back(u);
for(int v:rev[u]) {
if(visited[v]) continue;
cnt[v]++;
if(a[v] == A) {
q.push(v), visited[v] = 1;
} else {
if(cnt[v] == adj[v].sz) q.push(v), visited[v] = 1;
}
}
}
return ret;
}
vi getInv(vi x) {
vi y;
visited.reset();
for(int u:x) visited[u] = 1;
RE(u,n) if(!visited[u] && adj[u].sz) y.push_back(u);
return y;
}
void removeFromGraph(int u) {
for(int v:adj[u]) rev[v].erase(u);
for(int v:rev[u]) adj[v].erase(u);
adj[u].clear();
rev[u].clear();
}
vi who_wins(vi A, vi _R, vi U, vi V) {
a = A; r = _R; u = U; v = V;
n = a.size(); m = u.size();
res.resize(n);
RE(i,m) adj[u[i]].insert(v[i]);
RE(i,m) rev[v[i]].insert(u[i]);
RE(u,n) if(r[u]) R.push_back(u);
while(1) {
vi y = f(1, R);
vi x = getInv(y);
if(x.sz == 0) {
RE(u,n) if(adj[u].sz) res[u] = 1;
return res;
}
vi z = f(0,x);
for(int u:z) res[u] = 0;
for(int u:z) removeFromGraph(u);
}
}
Compilation message
train.cpp: In function 'vi f(bool, vi)':
train.cpp:51:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(cnt[v] == adj[v].sz) q.push(v), visited[v] = 1;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
1920 KB |
Output is correct |
2 |
Correct |
8 ms |
1920 KB |
Output is correct |
3 |
Correct |
7 ms |
1920 KB |
Output is correct |
4 |
Correct |
8 ms |
1920 KB |
Output is correct |
5 |
Correct |
7 ms |
1920 KB |
Output is correct |
6 |
Correct |
7 ms |
1920 KB |
Output is correct |
7 |
Correct |
7 ms |
1920 KB |
Output is correct |
8 |
Correct |
7 ms |
1920 KB |
Output is correct |
9 |
Correct |
7 ms |
1920 KB |
Output is correct |
10 |
Correct |
6 ms |
1792 KB |
Output is correct |
11 |
Correct |
5 ms |
1664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
896 KB |
Output is correct |
2 |
Correct |
1 ms |
896 KB |
Output is correct |
3 |
Correct |
1 ms |
896 KB |
Output is correct |
4 |
Correct |
1 ms |
896 KB |
Output is correct |
5 |
Correct |
1 ms |
896 KB |
Output is correct |
6 |
Correct |
1 ms |
896 KB |
Output is correct |
7 |
Correct |
1 ms |
896 KB |
Output is correct |
8 |
Correct |
1 ms |
896 KB |
Output is correct |
9 |
Correct |
1 ms |
896 KB |
Output is correct |
10 |
Correct |
1 ms |
896 KB |
Output is correct |
11 |
Correct |
1 ms |
896 KB |
Output is correct |
12 |
Correct |
1 ms |
896 KB |
Output is correct |
13 |
Correct |
1 ms |
896 KB |
Output is correct |
14 |
Correct |
1 ms |
896 KB |
Output is correct |
15 |
Correct |
1 ms |
896 KB |
Output is correct |
16 |
Correct |
1 ms |
896 KB |
Output is correct |
17 |
Correct |
1 ms |
896 KB |
Output is correct |
18 |
Correct |
1 ms |
896 KB |
Output is correct |
19 |
Correct |
1 ms |
896 KB |
Output is correct |
20 |
Correct |
1 ms |
896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
189 ms |
3456 KB |
Output is correct |
2 |
Correct |
327 ms |
3456 KB |
Output is correct |
3 |
Correct |
457 ms |
3576 KB |
Output is correct |
4 |
Correct |
16 ms |
3456 KB |
Output is correct |
5 |
Correct |
17 ms |
3504 KB |
Output is correct |
6 |
Correct |
18 ms |
3456 KB |
Output is correct |
7 |
Correct |
16 ms |
3472 KB |
Output is correct |
8 |
Correct |
17 ms |
3456 KB |
Output is correct |
9 |
Correct |
17 ms |
3328 KB |
Output is correct |
10 |
Correct |
16 ms |
3328 KB |
Output is correct |
11 |
Correct |
16 ms |
3200 KB |
Output is correct |
12 |
Correct |
14 ms |
3200 KB |
Output is correct |
13 |
Correct |
15 ms |
3456 KB |
Output is correct |
14 |
Correct |
21 ms |
3440 KB |
Output is correct |
15 |
Correct |
16 ms |
3456 KB |
Output is correct |
16 |
Correct |
23 ms |
3456 KB |
Output is correct |
17 |
Correct |
16 ms |
3456 KB |
Output is correct |
18 |
Correct |
443 ms |
2356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
2944 KB |
Output is correct |
2 |
Correct |
14 ms |
3072 KB |
Output is correct |
3 |
Correct |
18 ms |
3456 KB |
Output is correct |
4 |
Correct |
17 ms |
3456 KB |
Output is correct |
5 |
Correct |
17 ms |
3456 KB |
Output is correct |
6 |
Correct |
17 ms |
3328 KB |
Output is correct |
7 |
Correct |
17 ms |
3328 KB |
Output is correct |
8 |
Correct |
17 ms |
3328 KB |
Output is correct |
9 |
Correct |
14 ms |
3200 KB |
Output is correct |
10 |
Correct |
15 ms |
3456 KB |
Output is correct |
11 |
Correct |
22 ms |
3456 KB |
Output is correct |
12 |
Correct |
16 ms |
3456 KB |
Output is correct |
13 |
Correct |
17 ms |
3456 KB |
Output is correct |
14 |
Correct |
16 ms |
3168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
3456 KB |
Output is correct |
2 |
Correct |
15 ms |
3456 KB |
Output is correct |
3 |
Correct |
17 ms |
3456 KB |
Output is correct |
4 |
Correct |
15 ms |
3200 KB |
Output is correct |
5 |
Correct |
2 ms |
1152 KB |
Output is correct |
6 |
Correct |
7 ms |
1920 KB |
Output is correct |
7 |
Correct |
15 ms |
2944 KB |
Output is correct |
8 |
Correct |
17 ms |
3200 KB |
Output is correct |
9 |
Correct |
21 ms |
3072 KB |
Output is correct |
10 |
Correct |
5 ms |
1512 KB |
Output is correct |
11 |
Correct |
15 ms |
2816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
1920 KB |
Output is correct |
2 |
Correct |
8 ms |
1920 KB |
Output is correct |
3 |
Correct |
7 ms |
1920 KB |
Output is correct |
4 |
Correct |
8 ms |
1920 KB |
Output is correct |
5 |
Correct |
7 ms |
1920 KB |
Output is correct |
6 |
Correct |
7 ms |
1920 KB |
Output is correct |
7 |
Correct |
7 ms |
1920 KB |
Output is correct |
8 |
Correct |
7 ms |
1920 KB |
Output is correct |
9 |
Correct |
7 ms |
1920 KB |
Output is correct |
10 |
Correct |
6 ms |
1792 KB |
Output is correct |
11 |
Correct |
5 ms |
1664 KB |
Output is correct |
12 |
Correct |
1 ms |
896 KB |
Output is correct |
13 |
Correct |
1 ms |
896 KB |
Output is correct |
14 |
Correct |
1 ms |
896 KB |
Output is correct |
15 |
Correct |
1 ms |
896 KB |
Output is correct |
16 |
Correct |
1 ms |
896 KB |
Output is correct |
17 |
Correct |
1 ms |
896 KB |
Output is correct |
18 |
Correct |
1 ms |
896 KB |
Output is correct |
19 |
Correct |
1 ms |
896 KB |
Output is correct |
20 |
Correct |
1 ms |
896 KB |
Output is correct |
21 |
Correct |
1 ms |
896 KB |
Output is correct |
22 |
Correct |
1 ms |
896 KB |
Output is correct |
23 |
Correct |
1 ms |
896 KB |
Output is correct |
24 |
Correct |
1 ms |
896 KB |
Output is correct |
25 |
Correct |
1 ms |
896 KB |
Output is correct |
26 |
Correct |
1 ms |
896 KB |
Output is correct |
27 |
Correct |
1 ms |
896 KB |
Output is correct |
28 |
Correct |
1 ms |
896 KB |
Output is correct |
29 |
Correct |
1 ms |
896 KB |
Output is correct |
30 |
Correct |
1 ms |
896 KB |
Output is correct |
31 |
Correct |
1 ms |
896 KB |
Output is correct |
32 |
Correct |
189 ms |
3456 KB |
Output is correct |
33 |
Correct |
327 ms |
3456 KB |
Output is correct |
34 |
Correct |
457 ms |
3576 KB |
Output is correct |
35 |
Correct |
16 ms |
3456 KB |
Output is correct |
36 |
Correct |
17 ms |
3504 KB |
Output is correct |
37 |
Correct |
18 ms |
3456 KB |
Output is correct |
38 |
Correct |
16 ms |
3472 KB |
Output is correct |
39 |
Correct |
17 ms |
3456 KB |
Output is correct |
40 |
Correct |
17 ms |
3328 KB |
Output is correct |
41 |
Correct |
16 ms |
3328 KB |
Output is correct |
42 |
Correct |
16 ms |
3200 KB |
Output is correct |
43 |
Correct |
14 ms |
3200 KB |
Output is correct |
44 |
Correct |
15 ms |
3456 KB |
Output is correct |
45 |
Correct |
21 ms |
3440 KB |
Output is correct |
46 |
Correct |
16 ms |
3456 KB |
Output is correct |
47 |
Correct |
23 ms |
3456 KB |
Output is correct |
48 |
Correct |
16 ms |
3456 KB |
Output is correct |
49 |
Correct |
443 ms |
2356 KB |
Output is correct |
50 |
Correct |
12 ms |
2944 KB |
Output is correct |
51 |
Correct |
14 ms |
3072 KB |
Output is correct |
52 |
Correct |
18 ms |
3456 KB |
Output is correct |
53 |
Correct |
17 ms |
3456 KB |
Output is correct |
54 |
Correct |
17 ms |
3456 KB |
Output is correct |
55 |
Correct |
17 ms |
3328 KB |
Output is correct |
56 |
Correct |
17 ms |
3328 KB |
Output is correct |
57 |
Correct |
17 ms |
3328 KB |
Output is correct |
58 |
Correct |
14 ms |
3200 KB |
Output is correct |
59 |
Correct |
15 ms |
3456 KB |
Output is correct |
60 |
Correct |
22 ms |
3456 KB |
Output is correct |
61 |
Correct |
16 ms |
3456 KB |
Output is correct |
62 |
Correct |
17 ms |
3456 KB |
Output is correct |
63 |
Correct |
16 ms |
3168 KB |
Output is correct |
64 |
Correct |
17 ms |
3456 KB |
Output is correct |
65 |
Correct |
15 ms |
3456 KB |
Output is correct |
66 |
Correct |
17 ms |
3456 KB |
Output is correct |
67 |
Correct |
15 ms |
3200 KB |
Output is correct |
68 |
Correct |
2 ms |
1152 KB |
Output is correct |
69 |
Correct |
7 ms |
1920 KB |
Output is correct |
70 |
Correct |
15 ms |
2944 KB |
Output is correct |
71 |
Correct |
17 ms |
3200 KB |
Output is correct |
72 |
Correct |
21 ms |
3072 KB |
Output is correct |
73 |
Correct |
5 ms |
1512 KB |
Output is correct |
74 |
Correct |
15 ms |
2816 KB |
Output is correct |
75 |
Correct |
249 ms |
3704 KB |
Output is correct |
76 |
Correct |
380 ms |
3712 KB |
Output is correct |
77 |
Correct |
488 ms |
3712 KB |
Output is correct |
78 |
Correct |
486 ms |
3832 KB |
Output is correct |
79 |
Correct |
480 ms |
3728 KB |
Output is correct |
80 |
Correct |
16 ms |
3712 KB |
Output is correct |
81 |
Correct |
17 ms |
3712 KB |
Output is correct |
82 |
Correct |
18 ms |
3712 KB |
Output is correct |
83 |
Correct |
17 ms |
3712 KB |
Output is correct |
84 |
Correct |
18 ms |
3712 KB |
Output is correct |
85 |
Correct |
18 ms |
3712 KB |
Output is correct |
86 |
Correct |
18 ms |
3712 KB |
Output is correct |
87 |
Correct |
18 ms |
3712 KB |
Output is correct |
88 |
Correct |
26 ms |
3704 KB |
Output is correct |
89 |
Correct |
18 ms |
3712 KB |
Output is correct |
90 |
Correct |
26 ms |
3712 KB |
Output is correct |
91 |
Correct |
24 ms |
3712 KB |
Output is correct |
92 |
Correct |
41 ms |
3712 KB |
Output is correct |
93 |
Correct |
46 ms |
3712 KB |
Output is correct |
94 |
Correct |
38 ms |
3712 KB |
Output is correct |
95 |
Correct |
40 ms |
3712 KB |
Output is correct |
96 |
Correct |
132 ms |
3448 KB |
Output is correct |
97 |
Correct |
390 ms |
3720 KB |
Output is correct |
98 |
Correct |
595 ms |
3584 KB |
Output is correct |
99 |
Correct |
589 ms |
3584 KB |
Output is correct |
100 |
Correct |
430 ms |
2432 KB |
Output is correct |