#include "train.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e3 + 20;
int deg[maxn];
vector<int> adj[maxn];
int cnt[maxn];
int owner[maxn];
bool rem[maxn];
bool flag[maxn][2];
int n, m;
void bfs(int player) {
deque<int> q;
for (int i = 0; i < n; i++) {
if (flag[i][player]) {
q.push_back(i);
}
cnt[i] = 0;
}
while (!q.empty()) {
int u = q.front();
q.pop_front();
for (auto v: adj[u]) {
cnt[v]++;
if (owner[v] == player) {
if (cnt[v] == 1) {
flag[v][player] = true;
q.push_back(v);
}
}
else {
if (cnt[v] == deg[v]) {
flag[v][player] = true;
q.push_back(v);
}
}
}
}
}
vector<int> who_wins(vector<int> _owner, vector<int> charge, vector<int> u, vector<int> v) {
n = _owner.size();
for (int i = 0; i < n; i++) {
owner[i] = _owner[i];
}
m = u.size();
vector<int> res(n);
while (true) {
for (int i = 0; i < n; i++) {
deg[i] = 0;
adj[i].clear();
flag[i][0] = false;
flag[i][1] = false;
}
for (int i = 0; i < m; i++) {
if (!rem[u[i]] && !rem[v[i]]) {
deg[u[i]]++;
adj[v[i]].push_back(u[i]);
}
}
for (int i = 0; i < n; i++) {
if (!rem[i] && charge[i]) {
flag[i][1] = true;
}
}
bfs(1);
bool done = true;
for (int i = 0; i < n; i++) {
if (!rem[i] && !flag[i][1]) {
flag[i][0] = true;
done = false;
}
}
if (done) {
for (int i = 0; i < n; i++) {
if (!rem[i]) {
res[i] = 1;
}
}
break;
}
bfs(0);
for (int i = 0; i < n; i++) {
if (!rem[i] && flag[i][0]) {
res[i] = 0;
rem[i] = true;
}
}
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
852 KB |
3rd lines differ - on the 22nd token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Incorrect |
1 ms |
436 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
102 ms |
1344 KB |
Output is correct |
2 |
Correct |
228 ms |
1332 KB |
Output is correct |
3 |
Correct |
305 ms |
1348 KB |
Output is correct |
4 |
Correct |
6 ms |
1236 KB |
Output is correct |
5 |
Incorrect |
7 ms |
1236 KB |
3rd lines differ - on the 25th token, expected: '1', found: '0' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
1108 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 |
Incorrect |
6 ms |
1252 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
852 KB |
3rd lines differ - on the 22nd token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |