Submission #911846

#TimeUsernameProblemLanguageResultExecution timeMemory
911846Sir_Ahmed_ImranParachute rings (IOI12_rings)C++17
55 / 100
4043 ms165504 KiB
///~~~LOTA~~~/// #include <bits/stdc++.h> using namespace std; #define nl '\n' #define ff first #define ss second #define ll long long #define append push_back #define all(x) (x).begin(),(x).end() #define pii pair<int,int> #define MAXN 1000001 int n,x; int f[MAXN]; int par[MAXN]; vector<int> a[MAXN]; unordered_map<int,int> e; unordered_map<int,int> vis; void dfs(int v,int u,vector<int>& vec){ vis[v]=1; vec.append(v); for(auto& i:a[v]) if(!vis[i]) dfs(i,u,vec); if(vec.back()!=u) vec.pop_back(); } int root(int v){ if(par[v]==v) return v; par[v]=root(par[v]); return par[v]; } void join(int v,int u){ v=root(v); u=root(u); par[u]=v; f[v]+=f[u]; } bool same(int v,int u){ return (root(v)==root(u)); } void Init(int u){ n=x=u; for(int i=0;i<n;i++){ par[i]=i; e[i]=1; } } void Link(int v, int u){ if(!x) return; if(!f[root(v)] && same(v,u)){ vector<int> vec; dfs(v,u,vec); vis.clear(); x=0; map<int,int> z; for(auto& i:vec) z[i]=e[i]; e.clear(); for(auto& i:z){ if(i.ss){ x++; e[i.ff]=i.ss; } } } a[v].append(u); a[u].append(v); join(v,u); if(a[v].size()>3){ x=e[v]; e.clear(); e[v]=x; } if(a[u].size()>3){ x=e[u]; e.clear(); e[u]=x; } if(a[v].size()==3){ map<int,int> z; z[v]=e[v]; for(auto& i:a[v]) z[i]=e[i]; e.clear(); x=0; for(auto& i:z){ if(i.ss){ x++; e[i.ff]=i.ss; } } } if(a[u].size()==3){ map<int,int> z; z[u]=e[u]; for(auto& i:a[u]) z[i]=e[i]; e.clear(); x=0; for(auto& i:z){ if(i.ss){ x++; e[i.ff]=i.ss; } } } } int CountCritical(){ return x;; }
#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...