Submission #549586

#TimeUsernameProblemLanguageResultExecution timeMemory
549586Theo830Keys (IOI21_keys)C++17
9 / 100
107 ms31760 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1e9+7; const ll MOD = 998244353; typedef pair<ll,ll> ii; #define iii pair<ll,ii> #define f(i,a,b) for(ll i = a;i < b;i++) #define pb push_back #define vll vector<ll> #define F first #define S second #define all(x) (x).begin(), (x).end() ///I hope I will get uprating and don't make mistakes ///I will never stop programming ///sqrt(-1) Love C++ ///Please don't hack me ///@TheofanisOrfanou Theo830 ///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst) ///Stay Calm ///Look for special cases ///Beware of overflow and array bounds ///Think the problem backwards ///Training vector<ii>exo[20005]; bool v[20005]; ///keys ll p[20005]; ll siz[20005]; ll find_par(ll a){ if(p[a] == a){ return a; } return p[a] = find_par(p[a]); } void enose(ll a,ll b){ ll p1 = find_par(a); ll p2 = find_par(b); if(p1 != p2){ p[p1] = p2; siz[p2] += siz[p1]; siz[p1] = 0; } } 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); ll n = r.size(); ll m = u.size(); f(i,0,m){ exo[c[i]].pb(ii(u[i],v[i])); } ll timi[n]; ll mini = n + 100; f(i,0,n){ f(j,0,n){ v[j] = 0; p[j] = j; siz[j] = 1; } queue<ll>q; v[r[i]] = 1; q.push(r[i]); while(!q.empty()){ ll f = q.front(); q.pop(); for(auto x:exo[f]){ enose(x.F,x.S); if(!v[r[x.F]]){ v[r[x.F]] = 1; q.push(r[x.F]); } if(!v[r[x.S]]){ v[r[x.S]] = 1; q.push(r[x.S]); } } } timi[i] = siz[find_par(i)]; mini = min(mini,timi[i]); } f(i,0,n){ if(timi[i] != mini){ ans[i] = 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...