#include "train.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 5050;
vector<int> adj[N], rev[N];
bool ans[N], vis1[N], vis2[N];
int n, m, r[N];
void dfs1(int v) {
for (auto& x : adj[v]) {
if (!r[x] && !vis1[x]) vis1[x] = 1, dfs1(x);
}
}
void dfs2(int v) {
for (auto& x : rev[v]) {
if (!r[x] && !vis2[x]) vis2[x] = 1, dfs2(x);
}
}
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> _U, 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]);
}
for (int i = 0;i < n;i++) ::r[i] = r[i], ans[i] = 1;
for (int i = 0;i < n;i++) {
if (r[i]) continue;
memset(vis1, 0, sizeof vis1);
memset(vis2, 0, sizeof vis2);
dfs1(i);
dfs2(i);
bool ch = 0;
for (int j = 0;j < n;j++) if (vis1[j] && vis2[j]) ch = 1;
if (ch) {
for (int j = 0;j < n;j++) if (vis2[j]) ans[j] = 0;
}
}
vector<int> _ans(n);
for (int i = 0;i < n;i++) _ans[i] = ans[i];
return _ans;
}
/*
4 5
1 0 1 1
0 0 0 1
0 1
1 1
1 2
2 3
3 3
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
1112 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
604 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
250 ms |
1628 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
1372 KB |
3rd lines differ - on the 696th token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1715 ms |
1604 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
1112 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |