제출 #609583

#제출 시각아이디문제언어결과실행 시간메모리
609583Ozy열쇠 (IOI21_keys)C++17
0 / 100
1 ms340 KiB
#include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for (int i = (a); i <= (b); i++) #define repa(i,a,b) for (int i = (a); i >= (b); i--) #define lli long long int #define debug(a) cout << #a << " = " << a << endl #define debugsl(a) cout << #a << " = " << a << ", " #define MAX 2000 #define padre first #define num second vector<int> res; lli n,m,a,ini,act; pair<lli,lli> uf[MAX+2]; lli vis[MAX+2]; vector<pair<lli,lli> > aristas[MAX+2]; queue<lli> cola; vector<int> llaves[MAX+2]; lli sube(lli a) { if (uf[a].padre == a) return a; uf[a].padre = sube(uf[a].padre); return uf[a].padre; } void une(lli a ,lli b) { a = sube(a); b = sube(b); if (a==b) return; if (b == ini) swap(a,b); uf[b].padre = a; uf[a].num += uf[b].num; if (llaves[a].size() < llaves[b].size()) swap(llaves[a], llaves[b]); for (auto bb : llaves[b]) llaves[a].push_back(bb); } std::vector<int> find_reachable(std::vector<int> r, std::vector<int> u, std::vector<int> v, std::vector<int> c) { n = r.size(); m = u.size(); res.resize(n,0); rep(i,0,m-1) aristas[c[i]].push_back({u[i],v[i]}); rep(i,0,n-1) { ini = i; rep(j,0,n-1) { uf[j] = {j,1}; llaves[i].clear(); llaves[i].push_back(r[i]); } cola.push(r[i]); while (!cola.empty()) { act = cola.front(); cola.pop(); if (vis[act] == ini) continue; vis[act] = ini; for (auto k : aristas[act]) une(k.first,k.second); for (auto ll : llaves[ini]) if (vis[ll] != ini) cola.push(ll); llaves[ini].clear(); } res[i] = uf[i].num; } int peor = 1<<30; rep(i,0,n-1) peor = min(res[i],peor); rep(i,0,n-1) if (res[i] == peor) res[i] = 1; else res[i] = 0; return res; }
#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...