This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
map<array<int,3>,int> memo;
int que(int u, int v, int w) {
// cout<<"ask "<<u<<" "<<v<<" "<<w<<endl;
array<int,3> arr={u,v,w};
sort(arr.begin(),arr.end());
if(memo.count(arr)) return memo[arr];
// we can memo here
return memo[arr]=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;
int k=que(cen,u,x);
if(k==cen) {
assert(false);
} else if(k==u) {
if(sz[u]>1) cdc(u,x);
else {
vis[x]=true;
edges.insert({min(u,x),max(u,x)});
}
} else if(k==x) {
vis[x]=true;
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 {
vis[x]=true;
vis[k]=true;
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;
// cout<<"try : "<<i<<endl;
// for(auto [u,v]:edges) {
// cout<<u<<" "<<v<<endl;
// }
prep();
cdc(0,i);
}
for(auto [u,v]:edges) {
if(u>v) swap(u,v);
Bridge(u,v);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |