#include "train.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
int n;
vector< int > ans , g[N] , g2[N] , r , a;
void make(){
ans = vector< int > (n , -1);
vector< int > out(n , 0);
queue < int > q;
for(int i = 0 ;i < n;i++){
if(r[i]) continue;
for(int j = 0 ;j < (int)g[i].size();j++){
if(a[i]){
if(r[g[i][j]]){
out[i] = 0;
ans[i] = 1;
q.push(i);
break;
}
out[i]++;
}
else{
if(r[g[i][j]]) continue;
out[i]++;
}
}
if(out[i] == 0){
q.push(i);
if(ans[i] == -1){
ans[i] = a[i] ^ 1;
}
}
}
int node;
while(!q.empty()){
node = q.front();
q.pop();
for(int pre , i = 0 ;i < (int)g2[node].size();i++){
pre = g2[node][i];
if(out[pre] == 0 || r[pre]) continue;
out[pre]--;
if(ans[node] == a[pre]){
out[pre] = 0;
ans[pre] = a[pre];
q.push(pre);
continue;
}
if(out[pre] == 0){
ans[pre] = a[pre] ^ 1;
q.push(pre);
}
}
}
for(int i = 0 ;i < n;i++){
if(r[i]){
ans[i] = 1;
continue;
}
if(out[i] > 0){
ans[i] = 0;
}
}
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
n = (int)a.size();
ans.resize(n , -1);
::r = r;
::a = a;
for(int i = 0 ;i < (int)u.size();i++){
g[u[i]].push_back(v[i]);
g2[v[i]].push_back(u[i]);
}
bool found = true , good;
while(found){
make();
found = false;
for(int i = 0 ;i < n;i++){
if(!::r[i]) continue;
good = false;
for(int j = 0 ;j < (int)g[i].size();j++){
if(ans[g[i][j]] == a[i]){
good = true;
break;
}
}
if(good){
if(!a[i]) found = true, ::r[i] = false;
}
else{
if(a[i]) found = true, ::r[i] = false;
}
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
1108 KB |
3rd lines differ - on the 11th token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
468 KB |
3rd lines differ - on the 8th token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
1464 KB |
Output is correct |
2 |
Correct |
147 ms |
1680 KB |
Output is correct |
3 |
Correct |
199 ms |
1620 KB |
Output is correct |
4 |
Correct |
7 ms |
1620 KB |
Output is correct |
5 |
Correct |
11 ms |
1648 KB |
Output is correct |
6 |
Correct |
8 ms |
1620 KB |
Output is correct |
7 |
Correct |
6 ms |
1612 KB |
Output is correct |
8 |
Correct |
6 ms |
1620 KB |
Output is correct |
9 |
Correct |
5 ms |
1492 KB |
Output is correct |
10 |
Correct |
5 ms |
1572 KB |
Output is correct |
11 |
Correct |
6 ms |
1548 KB |
Output is correct |
12 |
Correct |
5 ms |
1492 KB |
Output is correct |
13 |
Correct |
6 ms |
1620 KB |
Output is correct |
14 |
Correct |
6 ms |
1576 KB |
Output is correct |
15 |
Correct |
6 ms |
1620 KB |
Output is correct |
16 |
Correct |
6 ms |
1620 KB |
Output is correct |
17 |
Correct |
6 ms |
1620 KB |
Output is correct |
18 |
Correct |
237 ms |
1284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1236 KB |
Output is correct |
2 |
Correct |
6 ms |
1492 KB |
Output is correct |
3 |
Correct |
7 ms |
1620 KB |
Output is correct |
4 |
Correct |
7 ms |
1576 KB |
Output is correct |
5 |
Correct |
6 ms |
1576 KB |
Output is correct |
6 |
Correct |
6 ms |
1620 KB |
Output is correct |
7 |
Correct |
6 ms |
1492 KB |
Output is correct |
8 |
Correct |
6 ms |
1492 KB |
Output is correct |
9 |
Correct |
6 ms |
1532 KB |
Output is correct |
10 |
Correct |
6 ms |
1584 KB |
Output is correct |
11 |
Correct |
6 ms |
1620 KB |
Output is correct |
12 |
Correct |
6 ms |
1576 KB |
Output is correct |
13 |
Correct |
6 ms |
1572 KB |
Output is correct |
14 |
Correct |
6 ms |
1444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
1364 KB |
3rd lines differ - on the 545th token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
1108 KB |
3rd lines differ - on the 11th token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |