#include "train.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn=5000+10;
vector<int>adj[maxn];
int n,shar[maxn],arez[maxn],m,dp[maxn],vas[maxn],dide[maxn];
void dfs(int u){
if(dide[u]){
return ;
}
dide[u]=1;
if(shar[u]==1){
vas[u]=1;
return ;
}
for(auto x:adj[u]){
dfs(x);
vas[u]|=vas[x];
}
return ;
}
bool ber(int u){
for(int i=0;i<n;i++){
vas[i]=dide[i]=0;
}
dfs(u);
return vas[u];
}
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();
m=(int)u.size();
for(int i=0;i<n;i++){
if(a[i]){
arez[i]=1;
}
if(r[i]){
shar[i]=1;
}
}
for(int i=0;i<m;i++){
adj[u[i]].push_back(v[i]);
}
for(int i=0;i<n;i++){
dp[i]=ber(i);
}
for(int asd=0;asd<=n;asd++){
for(int i=0;i<n;i++){
int cnt=0;
int f=0;
for(auto x:adj[i]){
if(x==i){
f=1;
continue;
}
if(dp[x]==1){
cnt++;
}
}
if(arez[i]){
if(f){
if(shar[i]==0&&cnt==0){
dp[i]=0;
}
}else{
if(cnt==0){
dp[i]=0;
}
}
}else{
if(f){
if(shar[i]==0||cnt!=(int)adj[i].size()-1){
dp[i]=0;
}
}else{
dp[i]=1;
}
}
}
}
vector<int>res(n);
for(int i=0;i<n;i++){
res[i]=dp[i];
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
103 ms |
860 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
3rd lines differ - on the 8th token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
210 ms |
1428 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
198 ms |
1368 KB |
3rd lines differ - on the 696th token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1034 ms |
1360 KB |
3rd lines differ - on the 2nd token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
103 ms |
860 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |