Submission #797475

#TimeUsernameProblemLanguageResultExecution timeMemory
797475firewaterSimurgh (IOI17_simurgh)C++14
51 / 100
132 ms2552 KiB
#include "simurgh.h" #include <cstdio> #include <cassert> #include <vector> #include <cstdlib> #include <string> #include<cstring> #include<iostream> #include<algorithm> using namespace std; #define N 1001000 #define mp make_pair #define fs first #define sn second int n,m,x,y,mx,w,xx,yy,sav,fa[N],p[N]; pair<int,int>a[N],l[N]; vector<int>ans; int find(int x) { return (fa[x]==x?x:fa[x]=find(fa[x])); } std::vector<int> find_roads(int nn, std::vector<int> u, std::vector<int> v) { n=nn; m=u.size(); for(int i=1;i<=m;++i) l[i]=mp(u[i-1]+1,v[i-1]+1); for(int k=1;k<=m;++k){ if(p[k])continue; for(int i=1;i<=n;++i) fa[i]=i; ans.clear(); ans.push_back(0); xx=l[k].fs; yy=l[k].sn; // printf("%d:--------------\n",k); for(int i=1;i<=m;++i){ x=find(l[i].fs); y=find(l[i].sn); // printf("%d %d\n",x,y); xx=find(xx); yy=find(yy); if(x!=y){ if((x==xx&&y==yy)||(x==yy&&y==xx))continue; fa[x]=y; ans.push_back(i-1); } } mx=0; w=0; xx=find(xx); yy=find(yy); sav=0; for(int i=1;i<=m;++i){ x=find(l[i].fs); y=find(l[i].sn); if((x==xx&&y==yy)||(x==yy&&y==xx)){ if(p[i]&&sav)continue; ans[0]=i-1; a[++w]=mp(i,count_common_roads(ans)); mx=max(mx,a[w].sn); if(p[i])sav=w; } } if(sav)mx=a[sav].sn+2-p[a[sav].fs]; for(int i=1;i<=w;++i) p[a[i].fs]=a[i].sn+2-mx; } ans.clear(); for(int i=1;i<=m;++i) if(p[i]==2)ans.push_back(i-1); 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...