Submission #978669

#TimeUsernameProblemLanguageResultExecution timeMemory
978669happy_nodeMeetings (JOI19_meetings)C++17
0 / 100
206 ms262144 KiB
#include "meetings.h" #include <bits/stdc++.h> using namespace std; const int MX=2005; set<pair<int,int>> edges; bool used[MX], vis[MX]; int sz[MX]; int N; vector<int> adj[MX]; int getSize(int v, int p) { sz[v]=1; for(auto u:adj[v]) { if(u!=p && !used[u]) { sz[v]+=getSize(u,v); } } return sz[v]; } int getCen(int v, int p, int s) { for(auto u:adj[v]) { if(u!=p && 2*sz[u]>s && !used[u]) { return getCen(u,v,s); } } return v; } int que(int u, int v, int w) { // cout<<"ask "<<u<<" "<<v<<" "<<w<<endl; // we can memo here return Query(u,v,w); } void cdc(int v, int x) { int s=getSize(v,v); int cen=getCen(v,v,s); getSize(cen,cen); used[cen]=true; bool fnd=0; for(auto u:adj[cen]) { if(used[u]) continue; if(que(cen,u,x)!=cen) { fnd=1; if(sz[u]>1) cdc(u,x); else { int k=que(cen,u,x); vis[k]=true; if(k!=cen) edges.insert({min(cen,k),max(cen,k)}); if(k!=u) edges.insert({min(u,k),max(u,k)}); if(k!=x) edges.insert({min(x,k),max(x,k)}); } break; } } if(!fnd) { vis[x]=true; edges.insert({min(cen,x),max(cen,x)}); } } void prep() { for(int i=0;i<N;i++) { used[i]=false; adj[i].clear(); } for(auto [u,v]:edges) { adj[u].push_back(v); adj[v].push_back(u); } } void Solve(int _N) { N=_N; vector<int> v; for(int i=0;i<N;i++) v.push_back(i); int k=que(0,1,2); vis[0]=true; vis[1]=true; vis[2]=true; vis[k]=true; if(k!=0) edges.insert({min(0,k),max(0,k)}); if(k!=1) edges.insert({min(1,k),max(1,k)}); if(k!=2) edges.insert({min(2,k),max(2,k)}); for(int i=3;i<N;i++) { if(vis[i]) continue; prep(); cdc(0,i); } for(auto [u,v]:edges) { // cout<<"final: "<<u<<" "<<v<<endl; if(u>v) swap(u,v); Bridge(u,v); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...