#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<bool> loop(n);
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]);
if (U[i] == V[i]) {
loop[U[i]] = true;
}
}
vector<int> stk;
vector<int> vis(n);
function<void(int)> dfs = [&](int v) {
vis[v] = 1;
for (int u : g[v]) {
if (!vis[u]) {
dfs(u);
}
}
stk.push_back(v);
};
for (int i = 0; i < n; ++i) {
if (!vis[i]) {
dfs(0);
}
}
set<pair<int, int>> se;
int ncc = 0;
function<void(int)> dfs2 = [&](int v) {
vis[v] = ncc;
for (int u : rg[v]) {
if (vis[u] == -1) {
dfs2(u);
} else if (vis[u] != ncc) {
se.emplace(vis[u], ncc);
}
}
};
fill(vis.begin(), vis.end(), -1);
for (int i = n - 1; i >= 0; --i) {
if (vis[stk[i]] == -1) {
dfs2(stk[i]);
ncc++;
}
}
vector<int> sz(ncc);
for (int i = 0; i < n; ++i) {
sz[vis[i]]++;
}
vector<bool> win(ncc);
for (int i = 0; i < n; ++i) {
if (r[i] && (loop[i] || sz[vis[i]] >= 3)) {
win[vis[i]] = true;
}
}
vector<vector<int>> sccg(ncc);
for (auto it : se) {
sccg[it.first].push_back(it.second);
}
vector<int> dp(ncc, -1);
function<int(int v)> dfs3 = [&](int v) -> int{
int& ret = dp[v];
if (ret != -1) {
return ret;
}
ret = win[v];
for (auto u : sccg[v]) {
ret |= dfs3(u);
}
return ret;
};
for (int i = 0; i < ncc; ++i) {
dfs3(i);
}
vector<int> res(n);
for (int i = 0; i < n; ++i) {
res[i] = dp[vis[i]];
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
1876 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
2004 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
1492 KB |
3rd lines differ - on the 696th token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
1652 KB |
3rd lines differ - on the 2nd token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
1876 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |