Submission #549597

#TimeUsernameProblemLanguageResultExecution timeMemory
549597Theo830Keys (IOI21_keys)C++17
9 / 100
93 ms30412 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 vis[2005]; 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] = {0}; ll mini = n + 100; f(i,0,n){ f(j,0,n){ vis[j] = 0; p[j] = j; siz[j] = 1; } queue<ll>q; vis[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(!vis[r[x.F]]){ vis[r[x.F]] = 1; q.push(r[x.F]); } if(!vis[r[x.S]]){ vis[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; } /* int main() { int n, m; assert(2 == scanf("%d%d", &n, &m)); std::vector<int> r(n), u(m), v(m), c(m); for(int i=0; i<n; i++) { assert(1 == scanf("%d", &r[i])); } for(int i=0; i<m; i++) { assert(3 == scanf("%d %d %d", &u[i], &v[i], &c[i])); } fclose(stdin); std::vector<int> ans = find_reachable(r, u, v, c); for (int i = 0; i < (int) ans.size(); ++i) { if(i) putchar(' '); putchar(ans[i]+'0'); } printf("\n"); 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...