제출 #1289607

#제출 시각아이디문제언어결과실행 시간메모리
1289607sirnick장난감 기차 (IOI17_train)C++20
0 / 100
5 ms2112 KiB
#include <bits/stdc++.h> using namespace std; 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<vector<int>> adj(n); for (int i = 0; i < m; i++) adj[u[i]].push_back(v[i]); vector<int> disc(n, -1), low(n), comp(n); vector<bool> onst(n, false); vector<int> st; int timer = 0, scc_count = 0; function<void(int)> dfs = [&](int u) { disc[u] = low[u] = timer++; st.push_back(u); onst[u] = true; for (int x : adj[u]) { if (disc[x] == -1) { dfs(x); low[u] = min(low[u], low[x]); } else if (onst[x]) { low[u] = min(low[u], disc[x]); } } if (low[u] == disc[u]) { while (true) { int w = st.back(); st.pop_back(); onst[w] = false; comp[w] = scc_count; if (w == u) break; } scc_count++; } }; for (int i = 0; i < n; i++) if (disc[i] == -1) dfs(i); vector<vector<int>> cadj(scc_count); vector<bool> has_charge(scc_count, false); for (int i = 0; i < n; i++) if (r[i]) has_charge[comp[i]] = true; for (int i = 0; i < m; i++) { int cu = comp[u[i]]; int cv = comp[v[i]]; if (cu != cv) cadj[cu].push_back(cv); } vector<vector<int>> rcadj(scc_count); for (int c = 0; c < scc_count; c++) for (int nx : cadj[c]) rcadj[nx].push_back(c); vector<int> win_scc(scc_count, false); queue<int> q; for (int c = 0; c < scc_count; c++) if (has_charge[c]) { win_scc[c] = true; q.push(c); } while (!q.empty()) { int c = q.front(); q.pop(); for (int p : rcadj[c]) if (!win_scc[p]) { win_scc[p] = true; q.push(p); } } vector<int> ans(n); for (int i = 0; i < n; i++) ans[i] = win_scc[comp[i]] ? 1 : 0; 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...