Submission #52076

#TimeUsernameProblemLanguageResultExecution timeMemory
52076aomeToy Train (IOI17_train)C++17
100 / 100
569 ms10600 KiB
#include "train.h" #include <bits/stdc++.h> using namespace std; const int N = 5005; int deg[N]; bool visit[N]; vector<int> G1[N], G2[N]; vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) { int n = a.size(), m = u.size(); for (int i = 0; i < m; ++i) { G1[u[i]].push_back(v[i]), G2[v[i]].push_back(u[i]); } vector<int> res(n, 0); while (1) { for (int i = 0; i < n; ++i) visit[i] = 0; queue<int> qu; for (int i = 0; i < n; ++i) { deg[i] = G1[i].size(); } for (int i = 0; i < n; ++i) { if (r[i]) qu.push(i); } while (qu.size()) { int u = qu.front(); qu.pop(); for (auto v : G2[u]) { if (a[v]) { if (!visit[v]) { visit[v] = 1; if (!r[v]) qu.push(v); } } else { deg[v]--; if (deg[v] == 0) { visit[v] = 1; if (!r[v]) qu.push(v); } } } } bool flag = 0; for (int i = 0; i < n; ++i) { if (r[i] && !visit[i]) { r[i] = 0, flag = 1; } } if (flag) continue; for (int i = 0; i < n; ++i) res[i] = visit[i]; break; } return res; }
#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...