#include <bits/stdc++.h>
//#include "train.h"
using namespace std;
typedef long long ll;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
#define pb push_back
#define popb pop_back
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
//std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v);
const int nax = 5004;
const int MOD = 1e9 + 7;
int n, m;
vi adj[nax];
int A[nax], C[nax];
int vis[nax][nax];
int dfs(int x, int dep )
{
if(vis[x][dep])
return 1;
if(dep == 0)
return 0;
vis[x][dep] = 1;
int ans = -1;
for(auto e: adj[x])
{
int rep;
int nw_dep = dep - 1;
if(C[e])
nw_dep = n;
if(vis[x][nw_dep])
rep = 1;
else
rep = dfs(e, nw_dep);
if(ans == -1)
ans = rep;
else
{
if(A[x])
if(rep == 1)
ans = 1;
if(!A[x])
if(rep == 0)
ans = 0;
}
}
vis[x][dep] = 0 ;
return ans;
}
vi who_wins(vi a, vi r, vi u, vi v)
{
n = a.size();
m = u.size();
for(int i = 0 ; i < n; i++)
{
A[i] = a[i];
C[i ] = r[i];
}
for(int i = 0 ; i < m; i ++)
{
adj[u[i]].pb(v[i]);
}
vi ans(n, 0);
for(int i = 0 ; i < n; i ++)
{
ans[i] = dfs(i, n);
}
return ans;
}
/*
int main() {
int n, m;
assert(2 == scanf("%d %d", &n, &m));
vector<int> a(n), r(n), u(m), v(m);
for(int i = 0; i < n; i++)
assert(1 == scanf("%d", &a[i]));
for(int i = 0; i < n; i++)
assert(1 == scanf("%d", &r[i]));
for(int i = 0; i < m; i++)
assert(2 == scanf("%d %d", &u[i], &v[i]));
vector<int> res = who_wins(a, r, u, v);
for(int i = 0; i < (int)res.size(); i++)
printf(i ? " %d" : "%d", res[i]);
printf("\n");
return 0;
}
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2077 ms |
1284 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2063 ms |
468 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2013 ms |
2612 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
21460 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 |
Execution timed out |
2053 ms |
21472 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2077 ms |
1284 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |