#include "train.h"
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define pb push_back
#define lb lower_bound
#define gibon ios::sync_with_stdio(false); cin.tie(0);
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
typedef long long ll;
using namespace std;
const int mxN=5005;
const int mxM=2200005;
const int mxK=61;
const int MOD=1e9+7;
const ll INF=1e18;
int N, M;
vector <int> adj[mxN];
vector <int> radj[mxN];
int AB[mxN];
bool imp[mxN];
int cnt;
void input(){
cin >> N >> M;
for(int i=0;i<N;i++) cin >> AB[i];
for(int i=0;i<N;i++) cin >> imp[i];
for(int i=0;i<M;i++){
int a, b;
cin >> a >> b;
adj[a].push_back(b);
radj[b].push_back(a);
}
}
void init(vector <int> a, vector<int> r, vector<int> u, vector<int> v){
N=a.size(), M=u.size();
for(int i=0;i<N;i++) AB[i]=a[i];
for(int i=0;i<N;i++) imp[i]=r[i];
for(int i=0;i<M;i++){
int t1=u[i], t2=v[i];
adj[t1].push_back(t2);
radj[t2].push_back(t1);
}
}
bool Chk[mxN];
bool bor[mxN];
int deg[mxN];
queue <int> que;
void solv_reachable(){
for(int i=0;i<N;i++) deg[i]=adj[i].size(), Chk[i]=false;
for(int i=0;i<N;i++) if(imp[i]) que.push(i), Chk[i]=true;
while(que.size()){
int now=que.front();
que.pop();
for(int x : radj[now]) if(!Chk[x]){
if(AB[x]==1){
Chk[x]=true;
que.push(x);
}
else{
deg[x]--;
if(deg[x]==0){
Chk[x]=true;
que.push(x);
}
}
}
}
for(int i=0;i<N;i++) bor[i]=(!Chk[i]);
}
void destroy_charge(){
for(int i=0;i<N;i++) deg[i]=adj[i].size(), Chk[i]=false;
for(int i=0;i<N;i++) if(bor[i]) que.push(i), Chk[i]=true;
while(que.size()){
int now=que.front();
que.pop();
for(int x : radj[now]) if(!Chk[x]){
if(AB[x]==0){
Chk[x]=true;
que.push(x);
}
else{
deg[x]--;
if(deg[x]==0){
Chk[x]=true;
que.push(x);
}
}
}
}
for(int i=0;i<N;i++) if(Chk[i]) imp[i]=false;
}
void solv(){
int pcnt=0;
for(int i=0;i<N;i++) if(imp[i]) pcnt++;
while(true){
solv_reachable();
destroy_charge();
int ncnt=0;
for(int i=0;i<N;i++) if(imp[i]) ncnt++;
if(pcnt==ncnt) break;
pcnt=ncnt;
}
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
init(a, r, u, v);
solv();
vector <int> res(N);
for(int i=0;i<N;i++) res[i]=(bor[i] ? 0 : 1);
return res;
}
/*
int main(){
input();
solv();
for(int i=0;i<N;i++) cout << (bor[i] ? 0 : 1) << " ";
}
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1364 KB |
Output is correct |
2 |
Correct |
5 ms |
1528 KB |
Output is correct |
3 |
Correct |
4 ms |
1364 KB |
Output is correct |
4 |
Correct |
7 ms |
1364 KB |
Output is correct |
5 |
Correct |
4 ms |
1364 KB |
Output is correct |
6 |
Correct |
4 ms |
1400 KB |
Output is correct |
7 |
Correct |
4 ms |
1364 KB |
Output is correct |
8 |
Correct |
4 ms |
1384 KB |
Output is correct |
9 |
Correct |
4 ms |
1364 KB |
Output is correct |
10 |
Correct |
4 ms |
1108 KB |
Output is correct |
11 |
Correct |
3 ms |
1108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
760 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
760 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
760 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
760 KB |
Output is correct |
18 |
Correct |
1 ms |
760 KB |
Output is correct |
19 |
Correct |
1 ms |
852 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
1984 KB |
Output is correct |
2 |
Correct |
79 ms |
1876 KB |
Output is correct |
3 |
Correct |
115 ms |
1964 KB |
Output is correct |
4 |
Correct |
6 ms |
1876 KB |
Output is correct |
5 |
Correct |
6 ms |
1720 KB |
Output is correct |
6 |
Correct |
6 ms |
1876 KB |
Output is correct |
7 |
Correct |
6 ms |
2044 KB |
Output is correct |
8 |
Correct |
6 ms |
1876 KB |
Output is correct |
9 |
Correct |
5 ms |
1876 KB |
Output is correct |
10 |
Correct |
6 ms |
1876 KB |
Output is correct |
11 |
Correct |
5 ms |
1620 KB |
Output is correct |
12 |
Correct |
6 ms |
1620 KB |
Output is correct |
13 |
Correct |
7 ms |
1876 KB |
Output is correct |
14 |
Correct |
6 ms |
1744 KB |
Output is correct |
15 |
Correct |
7 ms |
1876 KB |
Output is correct |
16 |
Correct |
6 ms |
1876 KB |
Output is correct |
17 |
Correct |
6 ms |
1876 KB |
Output is correct |
18 |
Correct |
174 ms |
1504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1620 KB |
Output is correct |
2 |
Correct |
7 ms |
1620 KB |
Output is correct |
3 |
Correct |
7 ms |
1876 KB |
Output is correct |
4 |
Correct |
7 ms |
1712 KB |
Output is correct |
5 |
Correct |
7 ms |
1844 KB |
Output is correct |
6 |
Correct |
7 ms |
1772 KB |
Output is correct |
7 |
Correct |
7 ms |
1876 KB |
Output is correct |
8 |
Correct |
6 ms |
1876 KB |
Output is correct |
9 |
Correct |
6 ms |
1732 KB |
Output is correct |
10 |
Correct |
6 ms |
1876 KB |
Output is correct |
11 |
Correct |
7 ms |
1876 KB |
Output is correct |
12 |
Correct |
6 ms |
1876 KB |
Output is correct |
13 |
Correct |
6 ms |
1876 KB |
Output is correct |
14 |
Correct |
6 ms |
1620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1876 KB |
Output is correct |
2 |
Correct |
7 ms |
1876 KB |
Output is correct |
3 |
Correct |
6 ms |
1876 KB |
Output is correct |
4 |
Correct |
7 ms |
1620 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
4 ms |
1108 KB |
Output is correct |
7 |
Correct |
4 ms |
1364 KB |
Output is correct |
8 |
Correct |
4 ms |
1576 KB |
Output is correct |
9 |
Correct |
4 ms |
1368 KB |
Output is correct |
10 |
Correct |
2 ms |
864 KB |
Output is correct |
11 |
Correct |
3 ms |
1476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1364 KB |
Output is correct |
2 |
Correct |
5 ms |
1528 KB |
Output is correct |
3 |
Correct |
4 ms |
1364 KB |
Output is correct |
4 |
Correct |
7 ms |
1364 KB |
Output is correct |
5 |
Correct |
4 ms |
1364 KB |
Output is correct |
6 |
Correct |
4 ms |
1400 KB |
Output is correct |
7 |
Correct |
4 ms |
1364 KB |
Output is correct |
8 |
Correct |
4 ms |
1384 KB |
Output is correct |
9 |
Correct |
4 ms |
1364 KB |
Output is correct |
10 |
Correct |
4 ms |
1108 KB |
Output is correct |
11 |
Correct |
3 ms |
1108 KB |
Output is correct |
12 |
Correct |
1 ms |
760 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
760 KB |
Output is correct |
18 |
Correct |
1 ms |
596 KB |
Output is correct |
19 |
Correct |
1 ms |
596 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
21 |
Correct |
1 ms |
596 KB |
Output is correct |
22 |
Correct |
1 ms |
596 KB |
Output is correct |
23 |
Correct |
1 ms |
596 KB |
Output is correct |
24 |
Correct |
1 ms |
596 KB |
Output is correct |
25 |
Correct |
1 ms |
760 KB |
Output is correct |
26 |
Correct |
1 ms |
596 KB |
Output is correct |
27 |
Correct |
1 ms |
596 KB |
Output is correct |
28 |
Correct |
1 ms |
760 KB |
Output is correct |
29 |
Correct |
1 ms |
760 KB |
Output is correct |
30 |
Correct |
1 ms |
852 KB |
Output is correct |
31 |
Correct |
1 ms |
596 KB |
Output is correct |
32 |
Correct |
53 ms |
1984 KB |
Output is correct |
33 |
Correct |
79 ms |
1876 KB |
Output is correct |
34 |
Correct |
115 ms |
1964 KB |
Output is correct |
35 |
Correct |
6 ms |
1876 KB |
Output is correct |
36 |
Correct |
6 ms |
1720 KB |
Output is correct |
37 |
Correct |
6 ms |
1876 KB |
Output is correct |
38 |
Correct |
6 ms |
2044 KB |
Output is correct |
39 |
Correct |
6 ms |
1876 KB |
Output is correct |
40 |
Correct |
5 ms |
1876 KB |
Output is correct |
41 |
Correct |
6 ms |
1876 KB |
Output is correct |
42 |
Correct |
5 ms |
1620 KB |
Output is correct |
43 |
Correct |
6 ms |
1620 KB |
Output is correct |
44 |
Correct |
7 ms |
1876 KB |
Output is correct |
45 |
Correct |
6 ms |
1744 KB |
Output is correct |
46 |
Correct |
7 ms |
1876 KB |
Output is correct |
47 |
Correct |
6 ms |
1876 KB |
Output is correct |
48 |
Correct |
6 ms |
1876 KB |
Output is correct |
49 |
Correct |
174 ms |
1504 KB |
Output is correct |
50 |
Correct |
5 ms |
1620 KB |
Output is correct |
51 |
Correct |
7 ms |
1620 KB |
Output is correct |
52 |
Correct |
7 ms |
1876 KB |
Output is correct |
53 |
Correct |
7 ms |
1712 KB |
Output is correct |
54 |
Correct |
7 ms |
1844 KB |
Output is correct |
55 |
Correct |
7 ms |
1772 KB |
Output is correct |
56 |
Correct |
7 ms |
1876 KB |
Output is correct |
57 |
Correct |
6 ms |
1876 KB |
Output is correct |
58 |
Correct |
6 ms |
1732 KB |
Output is correct |
59 |
Correct |
6 ms |
1876 KB |
Output is correct |
60 |
Correct |
7 ms |
1876 KB |
Output is correct |
61 |
Correct |
6 ms |
1876 KB |
Output is correct |
62 |
Correct |
6 ms |
1876 KB |
Output is correct |
63 |
Correct |
6 ms |
1620 KB |
Output is correct |
64 |
Correct |
6 ms |
1876 KB |
Output is correct |
65 |
Correct |
7 ms |
1876 KB |
Output is correct |
66 |
Correct |
6 ms |
1876 KB |
Output is correct |
67 |
Correct |
7 ms |
1620 KB |
Output is correct |
68 |
Correct |
1 ms |
596 KB |
Output is correct |
69 |
Correct |
4 ms |
1108 KB |
Output is correct |
70 |
Correct |
4 ms |
1364 KB |
Output is correct |
71 |
Correct |
4 ms |
1576 KB |
Output is correct |
72 |
Correct |
4 ms |
1368 KB |
Output is correct |
73 |
Correct |
2 ms |
864 KB |
Output is correct |
74 |
Correct |
3 ms |
1476 KB |
Output is correct |
75 |
Correct |
69 ms |
2040 KB |
Output is correct |
76 |
Correct |
92 ms |
1888 KB |
Output is correct |
77 |
Correct |
127 ms |
1876 KB |
Output is correct |
78 |
Correct |
140 ms |
1968 KB |
Output is correct |
79 |
Correct |
128 ms |
1876 KB |
Output is correct |
80 |
Correct |
7 ms |
1876 KB |
Output is correct |
81 |
Correct |
7 ms |
1856 KB |
Output is correct |
82 |
Correct |
6 ms |
1888 KB |
Output is correct |
83 |
Correct |
7 ms |
1876 KB |
Output is correct |
84 |
Correct |
7 ms |
1876 KB |
Output is correct |
85 |
Correct |
6 ms |
1876 KB |
Output is correct |
86 |
Correct |
6 ms |
1876 KB |
Output is correct |
87 |
Correct |
7 ms |
2044 KB |
Output is correct |
88 |
Correct |
11 ms |
1876 KB |
Output is correct |
89 |
Correct |
6 ms |
1876 KB |
Output is correct |
90 |
Correct |
11 ms |
1876 KB |
Output is correct |
91 |
Correct |
10 ms |
1876 KB |
Output is correct |
92 |
Correct |
17 ms |
2040 KB |
Output is correct |
93 |
Correct |
16 ms |
1876 KB |
Output is correct |
94 |
Correct |
17 ms |
1936 KB |
Output is correct |
95 |
Correct |
20 ms |
1944 KB |
Output is correct |
96 |
Correct |
42 ms |
1620 KB |
Output is correct |
97 |
Correct |
226 ms |
1876 KB |
Output is correct |
98 |
Correct |
353 ms |
1876 KB |
Output is correct |
99 |
Correct |
350 ms |
1876 KB |
Output is correct |
100 |
Correct |
168 ms |
1364 KB |
Output is correct |