Submission #406860

#TimeUsernameProblemLanguageResultExecution timeMemory
406860wiwihoToy Train (IOI17_train)C++14
11 / 100
1160 ms1740 KiB
#include "train.h" #include<bits/stdc++.h> #define printv(a, b) { \ for(auto pv : a) b << pv << " "; \ b << "\n"; \ } #define mp make_pair #define F first #define S second #define iter(a) a.begin(), a.end() #define lsort(a) sort(iter(a)) #define eb emplace_back using namespace std; typedef long long ll; using pii = pair<int, int>; const ll MAX = 1LL << 60; ostream& operator<<(ostream& o, pii p){ return o << '(' << p.F << ',' << p.S << ')'; } int n, m; vector<vector<int>> g, rg; vector<int> r; vector<int> t; vector<bool> vst; void dfs1(int now){ vst[now] = true; for(int i : rg[now]){ if(!r[i] && !vst[i]) dfs1(i); } t.eb(now); } vector<int> scc, sz; void dfs2(int now, int id){ scc[now] = id; sz[id]++; for(int i : g[now]){ if(!r[i] && scc[i] == -1) dfs2(i, id); } } vector<bool> c; bool ok = false; void dfs(int now){ vst[now] = true; //cerr << "owo " << now << "\n"; if(c[now]) ok = true; for(int i : g[now]){ if(!vst[i]) dfs(i); } } vector<int> who_wins(vector<int> a, vector<int> _r, vector<int> u, vector<int> v) { r = _r; n = a.size(), m = u.size(); c.resize(n); g.resize(n); rg.resize(n); for(int i = 0; i < m; i++){ if(u[i] == v[i]){ c[u[i]] = true; continue; } g[u[i]].eb(v[i]); rg[v[i]].eb(u[i]); } vst.resize(n); scc.resize(n, -1); sz.resize(n); for(int i = 0; i < n; i++){ if(r[i]) continue; if(!vst[i]) dfs1(i); } reverse(iter(t)); int ts = 0; for(int i : t){ if(r[i]) continue; if(scc[i] != -1) continue; dfs2(i, ts++); } //printv(scc, cerr); //printv(sz, cerr); for(int i = 0; i < n; i++){ if(r[i]){ c[i] = false; continue; } if(sz[scc[i]] > 1) c[i] = true; } //printv(c, cerr); vector<int> ans(n); for(int i = 0; i < n; i++){ ok = false; fill(iter(vst), false); //cerr << "test " << i << "\n"; dfs(i); ans[i] = !ok; } 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...