Submission #249131

#TimeUsernameProblemLanguageResultExecution timeMemory
249131MarcoMeijerToy Train (IOI17_train)C++14
11 / 100
17 ms4096 KiB
#include "train.h" #include <bits/stdc++.h> using namespace std; //macros typedef long long ll; typedef pair<int, int> ii; typedef pair<ll, ll> lll; typedef tuple<int, int, int> iii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<iii> viii; typedef vector<ll> vll; typedef vector<lll> vlll; #define REP(a,b,c) for(int a=int(b); a<int(c); a++) #define RE(a,c) REP(a,0,c) #define RE1(a,c) REP(a,1,c+1) #define REI(a,b,c) REP(a,b,c+1) #define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--) #define INF 1e9 #define pb push_back #define fi first #define se second #define sz size() const int MX=6000; int n, m; vi a, r, u, v; vi res; vi adj[MX], rev[MX]; bitset<MX> visited; stack<int> scS; int com[MX]; int scN=0; set<int> adjC[MX], revC[MX]; bitset<MX> rCom; int comSZ[MX]; int dp[MX]; void dfsSC1(int u) { if(visited[u]) return; visited[u] = 1; for(int v:adj[u]) dfsSC1(v); scS.push(u); } void dfsSC2(int u) { if(visited[u]) return; visited[u] = 1; com[u] = scN; comSZ[scN]++; for(int v:rev[u]) dfsSC2(v); } bool isLoop(int u) { if(comSZ[com[u]] > 1) return 1; for(int v:adj[u]) if(v == u) return 1; return 0; } void findSCB() { visited.reset(); RE(i,n) if(r[i] || a[i]) visited[i] = 1; RE(i,n) dfsSC1(i); visited.reset(); RE(i,n) if(r[i] || a[i]) visited[i] = 1; RE(i,n) com[i] = -1; while(!scS.empty()) { int u = scS.top(); scS.pop(); if(visited[u]) continue; comSZ[scN] = 0; dfsSC2(u); scN++; } RE(u,n) if(com[u] != -1) for(int v:adj[u]) if(com[v] != -1) if(com[u] != com[v]) adjC[com[u]].insert(com[v]); RE(u,n) if(com[u] != -1) for(int v:adj[u]) if(com[v] != -1) if(com[u] != com[v]) revC[com[v]].insert(com[u]); } void dfsB(int u) { if(res[u] == 0) return; if(a[u]) { bool all = 1; for(int v:adj[u]) if(res[v] == 1) all = 0; if(!all) return; } res[u] = 0; for(int v:rev[u]) { dfsB(v); } } void fillAllB() { RE(u,n) res[u] = 1; RE(u,n) if(com[u] != -1 && isLoop(u)) dfsB(u); } vi who_wins(vi A, vi R, vi U, vi V) { a = A; r = R; u = U; v = V; n = a.size(); m = u.size(); res.resize(n); RE(i,m) adj[u[i]].pb(v[i]); RE(i,m) rev[v[i]].pb(u[i]); findSCB(); fillAllB(); 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...