Submission #992019

#TimeUsernameProblemLanguageResultExecution timeMemory
9920198pete8September (APIO24_september)C++17
100 / 100
217 ms23920 KiB
#include "september.h" #include<iostream> #include <vector> #include<cassert> #include<set> #define pb push_back using namespace std; const int mxn=1e5,inf=1e9; int pa[mxn+10],group[mxn+10],comp,who[mxn+10],mnpos[mxn+10],group2[mxn+10],group3[mxn+10]; vector<int>adj[mxn+10]; int find(int u){return (pa[u]==u)?u:pa[u]=find(pa[u]);} void merg(int a,int b){ a=find(a),b=find(b); if(a==0||b==0)assert(0); if(a==b)return; comp--; pa[b]=a; group[a]=max(group[a],group[b]);//keep max del min } void dfs(int cur,int p){for(auto i:adj[cur])group3[i]=min(group2[i],group3[cur]),dfs(i,cur);} set<int>st; int solve(int n,int m,vector<int>up,vector<vector<int>>S){ for(int i=0;i<n;i++)pa[i]=i,group[i]=inf,group2[i]=inf,adj[i].clear(); for(int i=1;i<n;i++)adj[up[i]].pb(i); comp=n-1; st.clear(); for(int i=0;i<n;i++)st.insert(i); for(int i=0;i<n-1;i++){ int x=S[0][i]; group[x]=i; who[i]=x; } for(int i=0;i<n;i++)group2[i]=group[find(i)],group3[i]=group2[i]; dfs(0,-1); for(int i=0;i<n-1;i++){ int cur=S[0][i],mn=group3[cur]; int g=group2[(S[0][i])]; cur=mn; auto it=st.lower_bound(mn); while(it!=st.end()&&(*it)<g)merg(who[(*it)],who[g]),it=st.erase(it); } for(int j=1;j<m;j++){ int what=-1; for(int i=0;i<n-1;i++){ int x=group[find(S[j][i])]; auto it=st.lower_bound(x); while(it!=st.end()&&(*it)<what)merg(who[(*it)],who[what]),it=st.erase(it); what=max(what,x); } for(int i=0;i<n;i++)group2[i]=group[find(i)],group3[i]=group2[i]; dfs(0,-1); for(int i=0;i<n-1;i++){ int cur=S[j][i],mn=group3[cur]; int g=group2[(S[j][i])]; cur=g; auto it=st.lower_bound(mn); while(it!=st.end()&&(*it)<g)merg(who[(*it)],who[g]),it=st.erase(it); } } if(comp<=0)assert(0); return comp; } /* */
#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...
#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...