Submission #269528

#TimeUsernameProblemLanguageResultExecution timeMemory
269528khsoo01Toy Train (IOI17_train)C++11
100 / 100
443 ms1656 KiB
#include "train.h" #include<bits/stdc++.h> using namespace std; const int N = 5005; int n, deg[N], cur[N]; vector<int> adj[N], rev[N]; bool z[N]; vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) { vector<int> res; for(int i=0;i<(int)u.size();i++) { adj[u[i]].push_back(v[i]); rev[v[i]].push_back(u[i]); deg[u[i]]++; } n = a.size(); for(int i=0;i<n;i++) { z[i] = r[i]; } while(true) { queue<int> q; res.clear(); for(int i=0;i<n;i++) { cur[i] = 0; res.push_back(z[i]); if(z[i]) q.push(i); } while(!q.empty()) { int C = q.front(); q.pop(); for(auto &T : rev[C]) { ++cur[T]; if(!res[T] && ((a[T] && cur[T] == 1) || (!a[T] && cur[T] == deg[T]))) { res[T] = true; q.push(T); } } } bool upd = false; for(int i=0;i<n;i++) { if(!z[i]) continue; int C = 0; for(auto &T : adj[i]) { C += res[T]; } if((a[i] && C == 0) || (!a[i] && C != deg[i])) { z[i] = false; upd = true; } } if(!upd) break; } 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...