Submission #1076802

#TimeUsernameProblemLanguageResultExecution timeMemory
1076802zehnsechsToy Train (IOI17_train)C++14
100 / 100
258 ms1880 KiB
#include "train.h" #include<bits/stdc++.h> using namespace std; void dfs(int v, vector<int>& x, vector<int>& c, vector<vector<int>>& adj, vector<int>& res){ if(res[v]) return; res[v]=1; //cerr << "vertex " << v << '\n'; if(res[v]){ for(int u: adj[v]){ //cerr << "n " << u << '\n'; if (u==v) continue; c[u]--; if(c[u]==0 && !res[u]) { dfs(u,x,c,adj,res); } } } } vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) { int n = a.size(); int m = u.size(); vector<int> res(n,1); vector<vector<int>> adj(n); vector<int> deg(n,0); //add the edges to adj in the opposite direction for(int i=0;i<m;++i){ //cerr << "edge " << u[i] << ' ' << v[i] << '\n'; adj[v[i]].push_back(u[i]); deg[u[i]]++; } bool con = true; while(con){ con = false; vector<int> fa(n,0); vector<int> rm(n,0); vector<int> c0(n,1); vector<int> c1(n,1); for(int i=0;i<n;++i) (a[i] ? c1[i] = deg[i] : c0[i]= deg[i]); //cerr << "fa" << '\n'; for(int i=0;i<n;++i) if(r[i]&&res[i]) dfs(i,r,c0,adj,fa); vector<int> x(n,0); for(int i=0;i<n;++i) if(!fa[i]) x[i]=1; //cerr << "fb" << '\n'; for(int i=0;i<n;++i) if(!fa[i]&&res[i]) dfs(i,x,c1,adj,rm); for(int i=0;i<n;++i) if(rm[i]) { //cerr << "unreachable " << i <<'\n'; for(int u: adj[i]) deg[u]--; adj[i].clear(); res[i]=0; con = true; } } 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...