제출 #796659

#제출 시각아이디문제언어결과실행 시간메모리
796659Johann열쇠 (IOI21_keys)C++17
9 / 100
3067 ms28244 KiB
#include "bits/stdc++.h" using namespace std; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; typedef vector<pii> vpii; typedef vector<vpii> vvpii; typedef vector<bool> vb; #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() int N, M; vvpii adj; vi R; vi P; int find(int node) { vb keys(N, 0); keys[R[node]] = 1; vb vis(N, false); vis[node] = true; vvi waiting(N); queue<int> q; q.push(node); while (!q.empty()) { int v = q.front(), u, k; q.pop(); for (pii e : adj[v]) { tie(u, k) = e; if (vis[u]) continue; if (keys[k]) { vis[u] = true; q.push(u); if (!keys[R[u]]) { keys[R[u]] = true; while (!waiting[R[u]].empty()) { if (!vis[waiting[R[u]].back()]) q.push(waiting[R[u]].back()); waiting[R[u]].pop_back(); } } } else waiting[k].push_back(u); } } return accumulate(all(vis), 1); } std::vector<int> find_reachable(std::vector<int> r, std::vector<int> u, std::vector<int> v, std::vector<int> c) { N = sz(r), M = sz(u); R = r; adj.resize(N); for (int i = 0; i < sz(u); ++i) adj[u[i]].push_back({v[i], c[i]}), adj[v[i]].push_back({u[i], c[i]}); P.resize(N); for (int i = 0; i < N; ++i) P[i] = find(i); int mini = *min_element(all(P)); vi ans(N, 0); for (int i = 0; i < N; ++i) ans[i] = P[i] == mini; 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...