#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);
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:66:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for(int i=0;i<conds.size();i+=2) {
| ~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
1 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 |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 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 |
0 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 |
1 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 |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 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 |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 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 |
0 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 |
1 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 |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 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 |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 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 |
600 KB |
Output is correct |
28 |
Correct |
8 ms |
636 KB |
Output is correct |
29 |
Correct |
10 ms |
600 KB |
Output is correct |
30 |
Correct |
7 ms |
600 KB |
Output is correct |
31 |
Correct |
6 ms |
600 KB |
Output is correct |
32 |
Correct |
5 ms |
600 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 |
700 KB |
Output is correct |
36 |
Correct |
8 ms |
672 KB |
Output is correct |
37 |
Correct |
13 ms |
616 KB |
Output is correct |
38 |
Correct |
14 ms |
660 KB |
Output is correct |
39 |
Correct |
14 ms |
856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
530 ms |
2508 KB |
Output is correct |
2 |
Correct |
537 ms |
2768 KB |
Output is correct |
3 |
Correct |
528 ms |
2384 KB |
Output is correct |
4 |
Correct |
541 ms |
2544 KB |
Output is correct |
5 |
Correct |
422 ms |
2384 KB |
Output is correct |
6 |
Correct |
337 ms |
2128 KB |
Output is correct |
7 |
Correct |
397 ms |
2640 KB |
Output is correct |
8 |
Correct |
420 ms |
2380 KB |
Output is correct |
9 |
Correct |
400 ms |
2680 KB |
Output is correct |
10 |
Correct |
392 ms |
2544 KB |
Output is correct |
11 |
Correct |
447 ms |
2640 KB |
Output is correct |
12 |
Correct |
647 ms |
2860 KB |
Output is correct |
13 |
Correct |
590 ms |
2892 KB |
Output is correct |
14 |
Correct |
932 ms |
4236 KB |
Output is correct |
15 |
Correct |
827 ms |
4376 KB |
Output is correct |
16 |
Correct |
881 ms |
4688 KB |
Output is correct |
17 |
Correct |
365 ms |
2384 KB |
Output is correct |
18 |
Incorrect |
1272 ms |
7076 KB |
Wrong Answer [2] |
19 |
Halted |
0 ms |
0 KB |
- |