#include "train.h"
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) begin(a),end(a)
const int mxN = (int)20;
vi adj[mxN], v, a, r;
int vis[mxN];
bool recur(int s){
vis[s]=1; v.pb(s);
bool ok = 1;
for(auto u : adj[s]){
if(!vis[u]){
if(a[s]){
if(recur(u)) return 1;
ok = 0;
}
else ok&=recur(u);
}
else if(vis[u]==1){
int good = 0, pos = sz(v)-1;
while(pos>=0){
if(r[v[pos]]) good=1;
if(v[pos]==u) break;
pos--;
}
if(good and a[s]) return 1;
if(!good and !a[s]) return 0;
}
}
vis[s]=2; v.pop_back(); return ok;
}
vi who_wins(vi A, vi R, vi U, vi V) {
int n = sz(A), m = sz(U); vi ans(n,0);
for(int i = 0; i < n; i++) a[i]=A[i],r[i]=R[i];
for(int i = 0; i < m; i++) adj[U[i]].pb(V[i]);
for(int i = 0; i < n; i++) sort(all(adj[i]));
for(int i = 0; i < n; i++)
ans[i] = recur(i),memset(vis,0,sizeof(vis));
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
724 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
1236 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
980 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
5 ms |
1236 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
724 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |