Submission #70881

#TimeUsernameProblemLanguageResultExecution timeMemory
70881aquablitz11Toy Train (IOI17_train)C++14
100 / 100
892 ms15760 KiB
#include <bits/stdc++.h> #include "train.h" using namespace std; using pii = pair<int, int>; const int N = 5e3+10; vector<int> G[N], R[N]; int need[N]; bool win[N]; void dfs(int u, int r=0) { need[u] = 0; if (!r) win[u] = true; for (auto v : R[u]) if (--need[v] == 0) dfs(v, r); } vector<int> who_wins(vector<int> A, vector<int> C, vector<int> U, vector<int> V) { int n = A.size(); int m = U.size(); for (int i = 0; i < m; ++i) { G[U[i]].push_back(V[i]); R[V[i]].push_back(U[i]); } while (true) { // find all nodes that A can force to charger for (int u = 0; u < n; ++u) win[u] = false, need[u] = A[u] ? 1 : (int)G[u].size(); for (int u = 0; u < n; ++u) if (C[u] && need[u] > 0) dfs(u); // for nodes that A can't force, find which nodes B could force movement from for (int u = 0; u < n; ++u) need[u] = A[u] ? (int)G[u].size() : 1; for (int u = 0; u < n; ++u) if (!win[u] && need[u] > 0) dfs(u, 1); // if B could win on some charger, remove charger bool mod = false; for (int u = 0; u < n; ++u) if (need[u] <= 0 && C[u]) C[u] = false, mod = true; if (!mod) break; } vector<int> ans(n); for (int u = 0; u < n; ++u) if (need[u] > 0) ans[u] = 1; return ans; }
#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...