#include "train.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 5000;
int n,m;
vector<int> adj[N],rev[N];
bool sm[N],nxt[N];
bool visited[N],loop[N];
stack<int> st;
int id[N],idx;
void dfs(int u)
{
if(visited[u]) return;
visited[u] = true;
for(int v : adj[u]) dfs(v);
st.push(u);
}
void dfs2(int u,int p,int k)
{
if(u==p and k) loop[u] = true;
if(visited[u]) return;
visited[u] = true;
id[u] = idx;
for(int v : adj[u]) dfs2(v,u,1);
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v)
{
n = a.size(),m = u.size();
for(int i = 0;i < m;i++)
{
adj[u[i]].push_back(v[i]);
rev[v[i]].push_back(u[i]);
if(u[i]==v[i]) sm[u[i]] = true;
else nxt[u[i]] = true;
}
/* for(int i = 0;i < n;i++) if(!visited[i]) dfs(i);
for(int i = 0;i < n;i++) visited[i] = 0;
while(!st.empty())
{
int u = st.top();
st.pop();
if(visited[u]) continue;
++idx;
dfs2(u);
}*/
vector<int> ans(n);
for(int i = 0;i < n;i++)
{
dfs2(i,i,0);
for(int j = 0;j < n;j++) visited[j] = false;
}
for(int i = 0;i < n;i++)
{
for(int j = 0;j < n;j++) visited[j] = false;
dfs(i);
for(int j = 0;j < n;j++) if(r[j] and visited[j] and loop[j]) ans[i] = 1;
}
/*
for(int i = n-1;i >= 0;i--)
{
if(!nxt[i] and !sm[i]){ ans[i] = 0; continue; }
if(a[i] and r[i] and sm[i]) ans[i] = 1;
else if(a[i])
{
if(nxt[i]) ans[i] = ans[i+1];
else ans[i] = 0;
}
else
{
if(!r[i] and sm[i]) ans[i] = 0;
else if(sm[i] and !nxt[i]) ans[i] = 1;
else if(!nxt[i]) ans[i] = 0;
else ans[i] = ans[i+1];
}
}*/
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
746 ms |
52632 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
512 KB |
3rd lines differ - on the 2nd token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
556 ms |
52992 KB |
Output is correct |
2 |
Correct |
566 ms |
52984 KB |
Output is correct |
3 |
Correct |
585 ms |
52940 KB |
Output is correct |
4 |
Execution timed out |
2037 ms |
64384 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1958 ms |
85628 KB |
3rd lines differ - on the 696th token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2058 ms |
69052 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
746 ms |
52632 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |