# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
788400 |
2023-07-20T08:04:26 Z |
NeroZein |
Toy Train (IOI17_train) |
C++17 |
|
127 ms |
262144 KB |
#include "train.h"
#include "bits/stdc++.h"
using namespace std;
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> U, std::vector<int> V) {
int n = (int) a.size();
int m = (int) U.size();
vector<vector<int>> g(n);
vector<vector<int>> rg(n);
for (int i = 0; i < m; ++i) {
g[U[i]].push_back(V[i]);
rg[V[i]].push_back(U[i]);
}
vector<int> stk;
vector<int> vis(n);
function<void(int)> dfs = [&](int v) {
for (int u : g[v]) {
if (!vis[u]) {
dfs(u);
}
}
stk.push_back(v);
};
dfs(0);
int ncc = 0;
function<void(int)> dfs2 = [&](int v) {
vis[v] = ncc;
for (int u : rg[v]) {
if (vis[u] == -1) {
dfs2(u);
}
}
};
fill(vis.begin(), vis.end(), -1);
for (int i = n - 1; i >= 0; --i) {
if (vis[i] == -1) {
dfs2(i);
ncc++;
}
}
vector<bool> win(ncc);
for (int i = 0; i < n; ++i) {
if (r[i]) {
win[vis[i]] = true;
}
}
for (int i = n - 1; i >= 0; --i) {
for (int u : rg[i]) {
assert(vis[u] != -1 && vis[u] <= vis[i]);
win[vis[i]] = win[vis[i]] | win[vis[u]];
}
}
vector<int> res(n);
for (int i = 0; i < n; ++i) {
res[i] = win[vis[i]];
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
127 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
116 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
114 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
117 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
122 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
127 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |