#include "train.h"
#include<bits/stdc++.h>
using namespace std;
void dfs(int v, vector<int>& x, vector<int>& c, vector<vector<int>>& adj, vector<int>& res){
if (x[v]) res[v]=1;
if(res[v]){
for(int u: adj[v]){
c[u] --;
if(c[u]==0) {
res[u]=1;
dfs(u,x,c,adj,res);
}
}
}
}
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
int n = a.size();
int m = u.size();
vector<int> res(n,1);
vector<vector<int>> adj(n);
vector<int> deg(n,0);
//add the edges to adj in the opposite direction
for(int i=0;i<m;++i){
adj[v[i]].push_back(u[i]);
deg[u[i]]++;
}
bool con = true;
while(con){
con = false;
vector<int> fa(n,0);
vector<int> rm(n,0);
vector<int> c0(n,1);
vector<int> c1(n,1);
for(int i=0;i<n;++i) (a[i] ? c1[i] = deg[i] : c0[i]= deg[i]);
for(int i=0;i<n;++i) if(r[i]&&res[i]) dfs(i,r,c0,adj,fa);
for(int i=0;i<n;++i) if(!fa[i]&&res[i]) dfs(i,fa,c1,adj,rm);
for(int i=0;i<n;++i) if(rm[i]) {
res[i]=0;
con = true;
}
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 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 |
0 ms |
348 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 |
4 ms |
1628 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 |
5 ms |
1116 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 |
5 ms |
1372 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 |
3 ms |
860 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |