Submission #1064070

#TimeUsernameProblemLanguageResultExecution timeMemory
1064070TheQuantiXToy Train (IOI17_train)C++17
12 / 100
6 ms2140 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> get_total(vector<int> a, vector<int> r, vector<int> u, vector<int> v, vector<ll> cnt) { queue<ll> q; vector<int> vis(n); for (int i = 0; i < n; i++) { if (r[i]) { q.push(i); } } while (!q.empty()) { ll x = q.front(); q.pop(); if (vis[x]) { continue; } vis[x] = 1; for (auto i : G[x]) { if (a[i] && !vis[i]) { q.push(i); } if (!a[i]) { cnt[i]--; if (cnt[i] == 0 && !vis[i]) { q.push(i); } } } } return vis; } 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]); } vector<int> total = get_total(a, r, u, v, cnt); // for (int i = 0; i < n; i++) { // cout << total[i] << ' '; // } // cout << '\n'; vector<int> possible(n); auto cnt1 = cnt; for (int i = 0; i < n; i++) { if (r[i]) { bool fl; if (a[i]) { fl = 0; for (int j : Gr[i]) { if (total[j]) { fl = 1; break; } } } else { fl = 1; for (int j : Gr[i]) { if (!total[j]) { fl = 0; break; } } } possible[i] = fl; } } return get_total(a, possible, u, v, cnt); }
#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...