#include <bits/stdc++.h>
#include "train.h"
using namespace std;
typedef long long ll;
vector<unordered_set<ll>> adj, revAdj;
vector<bool> vst;
bool poss = false;
vector<int> a;
void dfs1(ll cur, ll root) {
vst[cur] = true;
for (auto &e : revAdj[cur]) {
if (e == root) poss = true;
if (vst[e]) continue;
dfs1(e, root);
}
}
void dfs2(ll cur, ll par, bool can) {
vst[cur] = true;
if (cur == par) {
for (auto &e : revAdj[cur]) {
if (vst[e]) continue;
dfs2(e, cur, true);
}
return;
}
if (a[cur] != can) {
if (adj[cur].size() > 1) {
adj[cur].erase(par);
for (auto &e : revAdj[cur]) {
if (vst[e]) continue;
dfs2(e, cur, !can);
}
}
else {
for (auto &e : revAdj[cur]) {
if (vst[e]) continue;
dfs2(e, cur, can);
}
}
}
else {
adj[cur].clear();
adj[cur].insert(par);
for (auto &e : revAdj[cur]) {
if (vst[e]) continue;
dfs2(e, cur, can);
}
}
}
vector<int> who_wins(vector<int> a1, vector<int> r, vector<int> u, vector<int> v) {
a = a1;
ll n = a.size(), m = u.size();
vector<int> res(n);
adj = vector<unordered_set<ll>>(n);
revAdj = vector<unordered_set<ll>>(n);
for (int i = 0; i < m; i++) {
adj[u[i]].insert(v[i]);
revAdj[v[i]].insert(u[i]);
}
ll charge = 0;
for (int i = 0; i < n; i++) {
if (r[i]) {
charge = i;
break;
}
}
vst = vector<bool>(n);
dfs2(charge, charge, true);
revAdj = vector<unordered_set<ll>>(n);
for (int i = 0; i < n; i++) {
for (auto &e : adj[i]) {
revAdj[e].insert(i);
}
}
vst = vector<bool>(n);
poss = false;
dfs1(charge, charge);
vector<bool> vst2 = vst;
if (poss) {
for (int j = 0; j < n; j++) {
if (!vst2[j]) continue;
res[j] = true;
}
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
2904 KB |
3rd lines differ - on the 14th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
3rd lines differ - on the 2nd token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
4700 KB |
Output is correct |
2 |
Correct |
11 ms |
4444 KB |
Output is correct |
3 |
Correct |
9 ms |
4464 KB |
Output is correct |
4 |
Correct |
17 ms |
4188 KB |
Output is correct |
5 |
Correct |
10 ms |
4212 KB |
Output is correct |
6 |
Incorrect |
11 ms |
3932 KB |
3rd lines differ - on the 47th token, expected: '1', found: '0' |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
3416 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
17 ms |
4188 KB |
3rd lines differ - on the 2nd token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
2904 KB |
3rd lines differ - on the 14th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |