Submission #94471

#TimeUsernameProblemLanguageResultExecution timeMemory
94471wxh010910Toy Train (IOI17_train)C++17
100 / 100
592 ms1528 KiB
#include <bits/stdc++.h> #include "train.h" using namespace std; vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) { int n = a.size(), m = u.size(); vector<vector<int>> adj(n); vector<int> deg(n); for (int i = 0; i < m; ++i) { adj[v[i]].push_back(u[i]); ++deg[u[i]]; } while (true) { vector<int> win = r; { vector<int> degree = deg; queue<int> q; for (int i = 0; i < n; ++i) { if (win[i]) { q.push(i); } } while (!q.empty()) { int x = q.front(); q.pop(); for (auto y : adj[x]) { if (!win[y]) { if (a[y] || !--degree[y]) { win[y] = 1; q.push(y); } } } } } { vector<int> degree = deg; queue<int> q; for (int i = 0; i < n; ++i) { if (!win[i]) { q.push(i); } } while (!q.empty()) { int x = q.front(); q.pop(); for (auto y : adj[x]) { if (win[y]) { if (!a[y] || !--degree[y]) { win[y] = 0; q.push(y); } } } } } bool changed = false; for (int i = 0; i < n; ++i) { if (r[i] && !win[i]) { changed = true; r[i] = 0; } } if (!changed) { return win; } } }
#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...