Submission #1064043

#TimeUsernameProblemLanguageResultExecution timeMemory
1064043TheQuantiXToy Train (IOI17_train)C++17
23 / 100
108 ms2136 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; constexpr ll INF = 1000000000000000000LL; ll n, m, q, k, x, y, a, c; vector<ll> G[5000]; vector<ll> Gr[5000]; vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) { n = a.size(); m = u.size(); vector<ll> cnt(n); vector<int> ans(n); for (int i = 0; i < n; i++) { G[i].clear(); Gr[i].clear(); } for (int i = 0; i < m; i++) { cnt[u[i]]++; G[v[i]].push_back(u[i]); Gr[u[i]].push_back(v[i]); } auto cnt1 = cnt; for (int i = 0; i < n; i++) { if (ans[i]) { continue; } if (r[i]) { cnt = cnt1; queue<ll> q; vector<int> vis(n); q.push(i); while (!q.empty()) { ll x = q.front(); q.pop(); if (vis[x]) { continue; } vis[x] = 1; for (auto j : G[x]) { if (a[j] && !vis[j]) { q.push(j); } if (!a[j]) { cnt[j]--; if (cnt[j] == 0 && !vis[j]) { q.push(j); } } } } bool fl; if (a[i]) { fl = 0; for (int j : Gr[i]) { if (vis[j]) { fl = 1; break; } } } else { fl = 1; for (int j : Gr[i]) { if (!vis[j]) { fl = 0; break; } } } if (fl) { for (int j = 0; j < n; j++) { ans[j] |= vis[j]; } } } } 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...