Submission #547475

#TimeUsernameProblemLanguageResultExecution timeMemory
547475blueToy Train (IOI17_train)C++17
11 / 100
10 ms1492 KiB
#include "train.h" #include <vector> #include <queue> #include <algorithm> #include <iostream> using namespace std; using vi = vector<int>; #define sz(x) int(x.size()) //a = owner, r = charging vi who_wins(vi a, vi r, vi U, vi V) { int n = sz(a); int m = sz(U); vi edge[n]; vi revedge[n]; for(int j = 0; j < m; j++) { edge[U[j]].push_back(V[j]); revedge[V[j]].push_back(U[j]); } vi good(n, 0); vi pushed(n, 0); queue<int> tbv; for(int i = 0; i < n; i++) { if(r[i]) { good[i] = 1; tbv.push(i); pushed[i] = 1; } } vi deg(n, 0); for(int j = 0; j < m; j++) deg[U[j]]++; // cerr << "done\n"; while(!tbv.empty()) { int u = tbv.front(); tbv.pop(); // cerr << "u = " << u << '\n'; for(int v : revedge[u]) { if(pushed[v]) continue; if(a[v] == 1) { pushed[v] = 1; tbv.push(v); good[v] = 1; } else { deg[v]--; if(deg[v] == 0) { pushed[v] = 1; tbv.push(v); good[v] = 1; } } } } // cerr << "checked\n"; while(1) { bool newreached = 0; for(int i = 0; i < n; i++) { if(!good[i]) continue; if(a[i] == 0) { good[i] = 1; for(int j : edge[i]) { if(!good[j]) good[i] = 0; } } else { good[i] = 0; for(int j : edge[i]) { if(good[j]) good[i] = 1; } } if(!good[i]) newreached = 1; } if(!newreached) break; } return good; }
#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...