Submission #549583

#TimeUsernameProblemLanguageResultExecution timeMemory
549583Theo830Keys (IOI21_keys)C++17
9 / 100
98 ms34820 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[2005]; bool v[2005]; ///keys ll p[2005]; ll siz[2005]; 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[x.F]){ v[x.F] = 1; q.push(x.F); } if(!v[x.S]){ v[x.S] = 1; q.push(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...