#include "train.h"
#include<bits/stdc++.h>
using namespace std;
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
int n = (int)a.size();
int m = (int)u.size();
vector<int>ans(n);
vector<vector<int>>adj(n);
for (int i = 0;i<m;++i){
adj[u[i]].push_back(v[i]);
}
vector<bool>in_cycle(n,false);
vector<bool>visited(n,false);
for (int i = 0;i<n;++i){
if (!r[i])continue;
vector<bool>parent(n,-1);
for (int j = 0;j<n;++j)visited[j] = false;
function<void(int)>dfs = [&](int u){
visited[u] = true;
for (auto x:adj[u]){
if (x == i){
int y = u;
while(y!=x){
in_cycle[y] = true;
y = parent[y];
}
}
else if (!visited[x]){
parent[x] = u;
dfs(x);
}
}
};
dfs(i);
}
for (int i = 0;i<n;++i){
visited[i] = false;
}
for (int i = 0;i<n;++i){
if (in_cycle[i]){
visited[i] = true;
ans[i] = true;
}
}
function<int(int)>dfs2 = [&](int u){
if (visited[u])return ans[u];
visited[u] = true;
int v = 0;
for (auto x:adj[u]){
v|=dfs2(x);
}
return ans[u] = v;
};
for (int i = 0;i<n;++i){
if (!visited[i]){
ans[i] = dfs2(i);
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
161 ms |
1144 KB |
3rd lines differ - on the 14th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2082 ms |
296 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
1372 KB |
Output is correct |
2 |
Correct |
41 ms |
1364 KB |
Output is correct |
3 |
Correct |
81 ms |
1344 KB |
Output is correct |
4 |
Execution timed out |
2085 ms |
1236 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2093 ms |
1108 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2073 ms |
1132 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
161 ms |
1144 KB |
3rd lines differ - on the 14th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |