#include "train.h"
#include <bits/stdc++.h>
using namespace std;
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 adj(N, vector<bool>(N));
for (int i = 0; i < M; i++) {
adj[U[i]][V[i]] = 1;
}
vector<int> ans(N);
for (int i = 0; i < N; i++) {
vector<int> p;
vector<bool> vis(N);
auto dfs = [&](auto dfs, int x) -> int {
p.push_back(x);
vis[x] = 1;
for (int y = 0; y < N; y++) {
if (adj[x][y]) {
if (!vis[y]) {
if (dfs(dfs, y) == A[x]) {
return A[x];
}
} else {
int cyc = 0;
for (int i = p.size() - 1; i >= 0; i--) {
cyc |= R[p[i]];
if (p[i] == y) {
break;
}
}
if (A[x] == cyc) {
return A[x];
}
}
}
}
vis[x] = 0;
p.pop_back();
return 1 - A[x];
};
ans[i] = dfs(dfs, i);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
139 ms |
3796 KB |
Output is correct |
2 |
Correct |
133 ms |
3796 KB |
Output is correct |
3 |
Correct |
137 ms |
3796 KB |
Output is correct |
4 |
Correct |
164 ms |
3820 KB |
Output is correct |
5 |
Correct |
126 ms |
3796 KB |
Output is correct |
6 |
Correct |
109 ms |
3796 KB |
Output is correct |
7 |
Correct |
93 ms |
3796 KB |
Output is correct |
8 |
Correct |
91 ms |
3796 KB |
Output is correct |
9 |
Correct |
74 ms |
3796 KB |
Output is correct |
10 |
Correct |
46 ms |
3796 KB |
Output is correct |
11 |
Correct |
28 ms |
3796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
3rd lines differ - on the 4th token, expected: '0', found: '1' |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2061 ms |
4052 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2071 ms |
4164 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2071 ms |
4096 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
139 ms |
3796 KB |
Output is correct |
2 |
Correct |
133 ms |
3796 KB |
Output is correct |
3 |
Correct |
137 ms |
3796 KB |
Output is correct |
4 |
Correct |
164 ms |
3820 KB |
Output is correct |
5 |
Correct |
126 ms |
3796 KB |
Output is correct |
6 |
Correct |
109 ms |
3796 KB |
Output is correct |
7 |
Correct |
93 ms |
3796 KB |
Output is correct |
8 |
Correct |
91 ms |
3796 KB |
Output is correct |
9 |
Correct |
74 ms |
3796 KB |
Output is correct |
10 |
Correct |
46 ms |
3796 KB |
Output is correct |
11 |
Correct |
28 ms |
3796 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Incorrect |
1 ms |
212 KB |
3rd lines differ - on the 4th token, expected: '0', found: '1' |
16 |
Halted |
0 ms |
0 KB |
- |