제출 #978706

#제출 시각아이디문제언어결과실행 시간메모리
978706happy_nodeMeetings (JOI19_meetings)C++17
0 / 100
286 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) { // cout<<"at node : "<<v<<endl; int s=getSize(v,v); // cout<<"size : "<<s<<endl; int cen=getCen(v,v,s); getSize(cen,cen); used[cen]=true; // cout<<"at cen : "<<cen<<endl; 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[x]=true; vis[k]=true; // cen -> u if(k==cen) { assert(false); } else if(k==u) { edges.insert({min(u,x),max(u,x)}); } else if(k==x) { edges.erase({min(u,cen),max(u,cen)}); edges.insert({min(cen,x),max(cen,x)}); edges.insert({min(u,x),max(u,x)}); } else { edges.erase({min(u,cen),max(u,cen)}); edges.insert({min(cen,k),max(cen,k)}); edges.insert({min(u,k),max(u,k)}); 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; vis[0]=true; for(int i=1;i<N;i++) { if(vis[i]) continue; prep(); cdc(0,i); } for(auto [u,v]:edges) { 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...