Submission #1022809

#TimeUsernameProblemLanguageResultExecution timeMemory
1022809shiomusubi496Toy Train (IOI17_train)C++17
0 / 100
7 ms1884 KiB
#include "train.h" #include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define rep2(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) #define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i) #define rrep2(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); --i) #define all(v) begin(v), end(v) using namespace std; template<class T, class U> bool chmin(T& a, const U& b) { return a > b ? a = b, true : false; } template<class T, class U> bool chmax(T& a, const U& b) { return a < b ? a = b, true : false; } using ll = long long; std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) { int n = a.size(), m = u.size(); queue<int> que; vector<vector<int>> g(n), rg(n); rep (i, m) { g[u[i]].push_back(v[i]); rg[v[i]].push_back(u[i]); } vector<int> cmp(n, -1); { vector<int> ord, used(n); auto dfs = [&](auto self, int v) -> void { used[v] = true; for (int u : g[v]) { if (!used[u]) self(self, u); } ord.push_back(v); }; rep (i, n) if (!used[i]) dfs(dfs, i); reverse(all(ord)); int k = 0; auto rdfs = [&](auto self, int v) -> void { cmp[v] = k; for (int u : rg[v]) { if (cmp[u] == -1) self(self, u); } }; for (int i : ord) { if (!cmp[i]) rdfs(rdfs, i), ++k; } } { vector<bool> memo(n); queue<int> que; rep (i, n) { if (a[i] == 0) { for (int j : g[i]) { if (cmp[i] != cmp[j]) { memo[i] = true; que.push(i); break; } } } else { memo[i] = true; for (int j : g[i]) { if (cmp[i] == cmp[j]) { memo[i] = false; break; } } if (memo[i]) que.push(i); } } vector<int> deg(n); rep (i, n) { if (cmp[u[i]] == cmp[v[i]]) ++deg[u[i]]; } while (!que.empty()) { int v = que.front(); que.pop(); for (int u : rg[v]) { if (memo[u]) continue; if (a[u] == 0 || (--deg[u]) == 0) { memo[u] = true; que.push(u); } } } rep (i, n) { if (memo[i]) r[i] = 0; } } { queue<int> que; rep (i, n) { if (r[i] == 1) que.push(i); } vector<int> deg(n); rep (i, n) ++deg[u[i]]; while (!que.empty()) { int v = que.front(); que.pop(); for (int u : rg[v]) { if (r[u]) continue; if (a[u] == 1 || (--deg[u]) == 0) { r[u] = true; que.push(u); } } } } return r; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...