#include <bits/stdc++.h>
#include "train.h"
using namespace std;
const int mxN = (int)5005;
vector<int>adj[mxN];
vector<int>radj[mxN];
vector<int>df;
vector<int>c(mxN);
int C = 0;
vector<bool>vis(mxN);
vector<bool>rvis(mxN);
void dfs(int u) {
df.push_back(u);
vis[u] = 1;
for(auto z : adj[u]) if(!vis[z]) {
dfs(z);
}
}
int cnt;
vector<bool>have(mxN);
vector<int>R;
void col(int u) {
cnt++;
c[u] = C;
rvis[u] = 1;
if(R[u])
have[C] = 1;
for(auto z : radj[u]) if(!rvis[z]) {
col(z);
}
}
vector<int>who_wins(vector<int>a, vector<int>r, vector<int>u, vector<int>v) {
int n = r.size();
int m = u.size();
R =r;
vector<bool>self(n,0);
for(int i = 0 ; i < m ; i++) {
adj[u[i]].push_back(v[i]);
radj[v[i]].push_back(u[i]);
if(v[i] == u[i])
self[v[i]] = 1;
}
dfs(0);
vector<bool>valid(n,1);
for(auto z : df) {
if(c[z]) continue;
C++;
cnt = 0;
col(z);
if(cnt == 1)
valid[z] = 0;
}
vector<int>ans(n,0);
for(int i = 0 ; i < n ; i++) {
vector<bool>t(n,0);
t[i] = 1;
stack<int>s;
s.push(i);
while(!s.empty()) {
int node = s.top();
s.pop();
if((have[c[node]] && valid[node]) || (self[node] && r[node])) {
ans[i] = 1;
break;
}
for(auto z : adj[node]) if(!t[z]) {
t[z] = 1;
s.push(z);
}
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
1364 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
468 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
1780 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
1364 KB |
3rd lines differ - on the 696th token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
1524 KB |
3rd lines differ - on the 2nd token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
1364 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |