#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;
vector<int> conds;
for(auto u:adj[cen]) {
if(used[u]) continue;
conds.push_back(u);
}
if(conds.size()&1) conds.push_back(cen);
assert(conds.size()<=20);
for(int i=0;i<conds.size();i+=2) {
int u=conds[i],v=conds[i+1];
if(que(u,v,x)!=cen) {
if(que(u,cen,x)!=cen) {
int k=que(u,cen,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)});
}
} else {
int k=que(v,cen,x);
if(k==cen) {
assert(false);
} else if(k==v) {
if(sz[v]>1) cdc(v,x);
else {
vis[x]=true;
edges.insert({min(v,x),max(v,x)});
}
} else if(k==x) {
vis[x]=true;
edges.erase({min(v,cen),max(v,cen)});
edges.insert({min(cen,x),max(cen,x)});
edges.insert({min(v,x),max(v,x)});
} else {
vis[x]=true;
vis[k]=true;
edges.erase({min(v,cen),max(v,cen)});
edges.insert({min(cen,k),max(cen,k)});
edges.insert({min(v,k),max(v,k)});
edges.insert({min(x,k),max(x,k)});
}
}
fnd=1;
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);
}
}
Compilation message
meetings.cpp: In function 'void cdc(int, int)':
meetings.cpp:67:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for(int i=0;i<conds.size();i+=2) {
| ~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
596 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
596 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
352 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
432 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
596 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
352 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
432 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
8 ms |
636 KB |
Output is correct |
28 |
Correct |
8 ms |
600 KB |
Output is correct |
29 |
Correct |
8 ms |
700 KB |
Output is correct |
30 |
Correct |
7 ms |
600 KB |
Output is correct |
31 |
Correct |
8 ms |
616 KB |
Output is correct |
32 |
Correct |
5 ms |
688 KB |
Output is correct |
33 |
Correct |
7 ms |
600 KB |
Output is correct |
34 |
Correct |
8 ms |
600 KB |
Output is correct |
35 |
Correct |
7 ms |
612 KB |
Output is correct |
36 |
Correct |
9 ms |
600 KB |
Output is correct |
37 |
Correct |
13 ms |
756 KB |
Output is correct |
38 |
Correct |
14 ms |
748 KB |
Output is correct |
39 |
Correct |
15 ms |
764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
562 ms |
2752 KB |
Output is correct |
2 |
Correct |
556 ms |
2520 KB |
Output is correct |
3 |
Correct |
550 ms |
2316 KB |
Output is correct |
4 |
Correct |
518 ms |
2560 KB |
Output is correct |
5 |
Correct |
436 ms |
2140 KB |
Output is correct |
6 |
Correct |
353 ms |
2056 KB |
Output is correct |
7 |
Correct |
397 ms |
2372 KB |
Output is correct |
8 |
Correct |
431 ms |
2420 KB |
Output is correct |
9 |
Correct |
407 ms |
2468 KB |
Output is correct |
10 |
Correct |
415 ms |
2740 KB |
Output is correct |
11 |
Correct |
447 ms |
2640 KB |
Output is correct |
12 |
Correct |
652 ms |
2704 KB |
Output is correct |
13 |
Correct |
587 ms |
3348 KB |
Output is correct |
14 |
Correct |
887 ms |
4196 KB |
Output is correct |
15 |
Correct |
853 ms |
4496 KB |
Output is correct |
16 |
Correct |
897 ms |
4308 KB |
Output is correct |
17 |
Correct |
373 ms |
2808 KB |
Output is correct |
18 |
Incorrect |
1254 ms |
6952 KB |
Wrong Answer [2] |
19 |
Halted |
0 ms |
0 KB |
- |