Submission #137572

#TimeUsernameProblemLanguageResultExecution timeMemory
137572ckodserSimurgh (IOI17_simurgh)C++14
0 / 100
180 ms3888 KiB
#include "simurgh.h" #include<bits/stdc++.h> #define ll int #define pb push_back #define mp make_pair #define ld long double #define F first #define S second #define pii pair<ll,ll> using namespace :: std; const ll maxn=510; const ll inf=1e9+900; ll d[maxn]; vector<ll> s,t; ll ger[maxn][maxn]; bool hast[maxn][maxn]; ll barg,N; ll findCnt(ll v,ll l,ll r){ vector<ll> t; for(ll i=l;i<r;i++){ if(i!=v && i!=barg){ t.pb(ger[v][i]); } } ll ans=0; ans-=hast[v][barg]; t.pb(ger[v][barg]); for(ll i=0;i<l;i++){ if(i!=v &&i!=barg){ t.pb(ger[barg][i]); ans-=hast[barg][i]; } } for(ll i=r;i<N;i++){ if(i!=v && i!=barg){ t.pb(ger[barg][i]); ans-=hast[barg][i]; } } ans+=count_common_roads(t); return ans; } void findHam(ll v,ll l,ll r,ll x){ if(x==0)return; if(l+1==r){ hast[v][l]=1; hast[l][v]=1; return; } ll mid=(l+r)/2; findHam(v,l,mid,findCnt(v,l,mid)); findHam(v,mid,r,findCnt(v,mid,r)); } vector<ll> solve(ll n){ barg=-1; for(ll i=0;i<n;i++){ vector<ll> r; for(ll j=0;j<n;j++){ if(j!=i){ r.pb(ger[i][j]); } } d[i]=count_common_roads(r); if(d[i]==1)barg=i; } for(ll i=0;i<n;i++){ if(i!=barg){ vector<ll> r; ll yeki=-1; for(ll j=0;j<n;j++){ if(j!=i && j!=barg){ yeki=j; r.pb(ger[i][j]); } } r.pb(ger[barg][yeki]); if(count_common_roads(r)==d[i]-1){ hast[barg][i]=1; hast[i][barg]=1; break; } } } for(ll i=0;i<n;i++){ if(i!=barg){ findHam(i,0,n,findCnt(i,0,n)); } } vector<ll> ans; for(ll i=0;i<n;i++){ for(ll j=i+1;j<n;j++){ if(hast[i][j]){ ans.pb(ger[i][j]); } } } return ans; } vector<int> find_roads(int n,vector<int> u,vector<int> v) { N=n; if(n==2){ vector<ll> ans; ans.pb(0); return ans; } memset(ger,-1,sizeof ger); s=v; t=u; ll m=v.size(); for(ll i=0;i<m;i++){ ger[s[i]][t[i]]=i; ger[t[i]][s[i]]=i; } if(m==(n*(n-1))/2){ return solve(n); } exit(1); }
#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...