제출 #1099239

#제출 시각아이디문제언어결과실행 시간메모리
1099239huyngo열쇠 (IOI21_keys)C++17
0 / 100
1 ms348 KiB
#include<bits/stdc++.h> using namespace std; std::vector<int> find_reachable(std::vector<int> r, std::vector<int> u, std::vector<int> v, std::vector<int> c) { std::vector<int> ans(r.size(), 1); int n = r.size(); int m = u.size(); vector<vector<array<int, 2>>> adj(n); vector<vector<int>> pend(n); for (int i = 0; i < m; ++i) { adj[u[i]].push_back({ v[i], c[i] }); adj[v[i]].push_back({ u[i], c[i] }); } vector<int> reachable(n); for (int st = 0; st < n; ++st) { vector<bool> unlock(n, false), vis(n, false); queue<int> qu; qu.push(st); vis[st] = true; while (qu.size()) { int u = qu.front(); qu.pop(); ++reachable[st]; unlock[r[u]] = true; for (int v : pend[r[u]]) if (!vis[v]) { vis[v] = true; qu.push(v); } pend[r[u]].clear(); for (auto [v, w] : adj[u]) if (!vis[v]) { if (unlock[w]) { vis[v] = true; qu.push(v); } else pend[w].push_back(v); } } } int _min = *min_element(reachable.begin(), reachable.end()); for (int i = 0; i < n; ++i) ans[i] = (reachable[i] == _min); 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...