#include "train.h"
#include<bits/stdc++.h>
using namespace std;
#define sz(a) (int)(a.size())
vector<int>g[2000],gr[2000];
std::vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
int n = sz(a);
vector<int>win(n,0);
for(int i=0;i<sz(u);i++){
g[u[i]].push_back(v[i]);
gr[v[i]].push_back(u[i]);
}
for(int i=0;i<n;i++){
if(!r[i])continue;
vector<bool>path(n,0);
vector<int>cnt(n,0);
for(int j=0;j<n;j++){
if(!a[j])cnt[j] = sz(g[j]);
}
queue<int>q;
q.push(i);
path[i] = 1;
while(!q.empty()){
int v = q.front();
q.pop();
for(int x:gr[v]){
if(path[x])continue;
if(a[x]){
path[x] = 1;
q.push(x);
}else{
cnt[x]--;
if(!cnt[x]){
path[x] = 1;
q.push(x);
}
}
}
}
//path(x) = x can be forced to go to i
bool cyc = 0;
int c = 0;
for(int x:g[i]){
if(path[x] && a[i])cyc = 1;
if(path[x] && !a[i])c++;
}
if(c == sz(g[i]))cyc = 1;
if(cyc){
for(int j=0;j<n;j++){
if(path[j])win[j] = 1;
}
}
}
vector<int>cnt(n,0);
queue<int>q;
for(int i=0;i<n;i++){
cnt[i] = sz(g[i]);
if(win[i])q.push(i);
}
while(!q.empty()){
int v = q.front();
q.pop();
for(int x:gr[v]){
if(win[x])continue;
if(a[x]){
win[x] = 1;
q.push(x);
}else{
cnt[x]--;
if(!cnt[x]){
win[x] = 1;
q.push(x);
}
}
}
}
return win;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
1112 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
3rd lines differ - on the 2nd token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
1628 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
1368 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
6 ms |
1628 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
1112 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |