# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
575389 |
2022-06-10T10:07:19 Z |
KoD |
Toy Train (IOI17_train) |
C++17 |
|
2000 ms |
1492 KB |
#include "train.h"
#include <bits/stdc++.h>
using ll = long long;
using std::vector;
using std::array;
using std::pair;
using std::tuple;
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
const int n = (int)a.size();
const int m = (int)u.size();
vector<int> ret(n, -1);
vector<vector<int>> graph(n), rev_graph(n);
for (int i = 0; i < m; ++i) {
graph[u[i]].push_back(v[i]);
graph[v[i]].push_back(u[i]);
}
const auto expand = [&](vector<char>& set, const int side) {
vector<int> deg(n);
std::queue<int> que;
for (int u = 0; u < n; ++u) {
for (const int v : graph[u]) {
if (ret[v] == -1) {
deg[u] += 1;
}
}
if (set[u]) {
que.push(u);
}
}
while (!que.empty()) {
const int u = que.front();
que.pop();
for (const int v : rev_graph[u]) {
if (ret[v] != -1 or set[v]) {
continue;
}
if (a[v] == side) {
set[v] = true;
que.push(v);
} else {
deg[v] -= 1;
if (deg[v] == 0) {
set[v] = true;
que.push(v);
}
}
}
}
};
while (true) {
if (std::all_of(ret.begin(), ret.end(), [&](const int x) { return x != -1; })) {
return ret;
}
vector<char> A_set(n);
for (int u = 0; u < n; ++u) {
if (ret[u] != -1 and r[u]) {
A_set[u] = true;
}
}
expand(A_set, 1);
bool A_win = true;
for (int u = 0; u < n; ++u) {
if (ret[u] != -1 and !A_set[u]) {
A_win = false;
break;
}
}
if (A_win) {
for (int u = 0; u < n; ++u) {
if (A_set[u]) {
ret[u] = 1;
}
}
} else {
vector<char> B_set(n);
for (int u = 0; u < n; ++u) {
if (ret[u] != -1 and !A_set[u]) {
B_set[u] = true;
}
}
expand(B_set, 0);
for (int u = 0; u < n; ++u) {
if (B_set[u]) {
ret[u] = 0;
}
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2055 ms |
980 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2067 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2062 ms |
1492 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2074 ms |
1236 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2035 ms |
1492 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2055 ms |
980 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |