Submission #717172

#TimeUsernameProblemLanguageResultExecution timeMemory
717172Jarif_RahmanToy Train (IOI17_train)C++17
0 / 100
992 ms2228 KiB
#include "train.h" #include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; int n, m, k; vector<vector<int>> graph, G, GR; vector<bool> bl; vector<int> order; vector<int> cid; vector<vector<int>> comp; vector<bool> self_loop; void dfs(int nd){ if(bl[nd]) return; bl[nd] = 1; for(int x: G[nd]) dfs(x); order.pb(nd); } void dfs2(int nd){ if(cid[nd] != -1) return; cid[nd] = int(comp.size())-1; comp.back().pb(nd); for(int x: GR[nd]) dfs2(x); } void dfs3(int nd){ if(bl[nd]) return; bl[nd] = 1; for(int x: graph[nd]) dfs3(x); } vector<int> who_wins(vector<int> A, vector<int> R, vector<int> U, vector<int> V){ n = A.size(), m = U.size(); graph.resize(n), G.resize(n), GR.resize(n); bl.assign(n, 0); cid.assign(n, -1); self_loop.assign(n, 0); for(int i = 0; i < m; i++){ graph[U[i]].pb(V[i]); if(R[U[i]] || R[V[i]]) continue; if(U[i] == V[i]){ self_loop[U[i]] = 1; continue; } G[U[i]].pb(V[i]), GR[V[i]].pb(U[i]); } for(int i = 0; i < n; i++) if(!bl[i]) dfs(i); reverse(order.begin(), order.end()); for(int x: order) if(cid[x] == -1){ comp.pb({}); dfs2(x); } k = comp.size(); vector<bool> non_charger(n, 0); for(int i = 0; i < k; i++){ if(comp[i].size() > 1 || (comp[i].size() == 1 && self_loop[comp[i][0]])){ for(int x: comp[i]) non_charger[x] = 1; } } vector<int> ans; for(int i = 0; i < n; i++){ bl.assign(n, 0); dfs3(i); bool ok = 0; for(int j = 0; j < n; j++) if(bl[j] && non_charger[j]) ok = 1; ans.pb(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...