#include "train.h"
#include <bits/stdc++.h>
using ll = long long;
using std::vector;
using std::array;
using std::pair;
using std::tuple;
template <class F> struct fixed : private F {
fixed(F&& f) : F(std::forward<F>(f)) {}
template <class... Args> decltype(auto) operator()(Args&&... args) const {
return F::operator()(*this, std::forward<Args>(args)...);
}
};
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
const int n = a.size();
const int m = u.size();
vector<char> loop(n);
vector<vector<int>> graph(n), rgraph(n);
for (int i = 0; i < m; ++i) {
if (u[i] == v[i]) {
loop[u[i]] = true;
}
graph[u[i]].push_back(v[i]);
rgraph[v[i]].push_back(u[i]);
}
vector<char> vis(n);
vector<int> stack;
for (int u = 0; u < n; ++u) {
fixed([&](auto&& dfs, const int u) -> void {
if (r[u] or vis[u]) return;
vis[u] = true;
for (const int v : graph[u]) {
dfs(v);
}
stack.push_back(u);
})(u);
}
std::fill(vis.begin(), vis.end(), false);
vector<vector<int>> group;
while (!stack.empty()) {
const int u = stack.back();
stack.pop_back();
if (vis[u]) continue;
auto& list = group.emplace_back();
fixed([&](auto&& dfs, const int u) -> void {
if (r[u] or vis[u]) return;
vis[u] = true;
for (const int v : rgraph[u]) {
dfs(v);
}
list.push_back(u);
})(u);
}
vector<int> ret(n, 1);
for (const auto& list : group) {
if (list.size() == 1) {
const int u = list[0];
if (loop[u]) {
ret[u] = 0;
}
} else {
for (const int u : list) {
ret[u] = true;
}
}
}
std::fill(vis.begin(), vis.end(), false);
for (int u = 0; u < n; ++u) {
fixed([&](auto&& dfs, const int u) -> void {
if (vis[u]) return;
vis[u] = true;
for (const int v : graph[u]) {
dfs(v);
}
stack.push_back(u);
})(u);
}
std::fill(vis.begin(), vis.end(), false);
group.clear();
while (!stack.empty()) {
const int u = stack.back();
stack.pop_back();
if (vis[u]) continue;
auto& list = group.emplace_back();
fixed([&](auto&& dfs, const int u) -> void {
if (vis[u]) return;
vis[u] = true;
for (const int v : rgraph[u]) {
dfs(v);
}
list.push_back(u);
})(u);
}
while (!group.empty()) {
auto list = std::move(group.back());
group.pop_back();
bool found = false;
for (const int u : list) {
for (const int v : graph[u]) {
if (ret[v] == 0) {
ret[u] = 0;
}
}
if (ret[u] == 0) {
found = true;
}
}
if (found) {
for (const int u : list) {
ret[u] = 0;
}
}
}
return ret;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
1596 KB |
3rd lines differ - on the 14th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
3rd lines differ - on the 2nd token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
1976 KB |
Output is correct |
2 |
Correct |
7 ms |
1876 KB |
Output is correct |
3 |
Correct |
7 ms |
1884 KB |
Output is correct |
4 |
Incorrect |
8 ms |
1748 KB |
3rd lines differ - on the 1st token, expected: '1', found: '0' |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1448 KB |
Output is correct |
2 |
Correct |
8 ms |
1748 KB |
Output is correct |
3 |
Correct |
10 ms |
1876 KB |
Output is correct |
4 |
Incorrect |
9 ms |
1720 KB |
3rd lines differ - on the 110th token, expected: '0', found: '1' |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
1724 KB |
3rd lines differ - on the 2nd token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
1596 KB |
3rd lines differ - on the 14th token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |