# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1060355 |
2024-08-15T13:20:24 Z |
Zicrus |
Toy Train (IOI17_train) |
C++17 |
|
11 ms |
8540 KB |
#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.clear();
for (int i = 0; i < n; i++) {
for (auto &e : adj[i]) {
revAdj[e].insert(i);
}
}
vst = vector<bool>(n);
dfs1(charge, charge);
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
5 ms |
5212 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
0 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
10 ms |
8540 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
10 ms |
6236 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
11 ms |
7516 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
5 ms |
5212 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |