Submission #495378

#TimeUsernameProblemLanguageResultExecution timeMemory
495378GiantpizzaheadKeys (IOI21_keys)C++17
9 / 100
3095 ms95016 KiB
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = (a); i < (b); i++) #define sz(x) ((int) x.size()) #define all(x) x.begin(), x.end() #define debug if (false) cerr using namespace std; using ll = long long; const int MAXN = 6e5+10; int N, M; vector<int> R, ans, ds; unordered_map<int, vector<int>> adj[MAXN]; void dfs(int i) { unordered_map<int, vector<int>> active; vector<int> toVisit; vector<bool> vis(N); toVisit.push_back(i); int numVis = 0; while (!toVisit.empty()) { int n = toVisit.back(); toVisit.pop_back(); if (vis[n]) continue; vis[n] = true; numVis++; for (auto& p : adj[n]) { auto& v = active[p.first]; v.insert(v.end(), all(p.second)); } if (active.count(R[n])) { for (int e : active[R[n]]) { toVisit.push_back(e); } active.erase(R[n]); } } ans[i] = numVis; } vector<int> find_reachable(vector<int> r, vector<int> u, vector<int> v, vector<int> c) { N = sz(r), M = sz(u); R = r; ans.resize(N); rep(i, 0, M) { adj[u[i]][c[i]].push_back(v[i]); adj[v[i]][c[i]].push_back(u[i]); } int minAns = MAXN; rep(i, 0, N) { dfs(i); minAns = min(ans[i], minAns); } rep(i, 0, N) ans[i] = (ans[i] == minAns); return ans; } /* int main() { ios::sync_with_stdio(0); cin.tie(0); vector<int> r{0,1,1,2}; vector<int> u{0,0,1,1,3}; vector<int> v{1,2,2,3,1}; vector<int> c{0,0,1,0,2}; vector<int> ans = find_reachable(r,u,v,c); rep(i, 0, sz(ans)) cout << ans[i] << " \n"[i==sz(ans)-1]; return 0; } */
#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...