QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#747286 | #63. Meetings | Shumomo | 0 | 1ms | 4220kb | C++14 | 2.3kb | 2024-11-14 16:47:33 | 2024-11-14 16:47:33 |
answer
#include "meetings.h"
#include<bits/stdc++.h>
using namespace std;
int nw,rt,num,sz[2009],vis[2009],mm[2009];
set<int> s[2009];
void fr(int x,int fa){
sz[x]=1;
mm[x]=0;
for(auto i:s[x]){
if(!vis[i]&&i!=fa){
fr(i,x);
sz[x]+=sz[i];
mm[x]=max(mm[x],sz[i]);
}
}
mm[x]=max(mm[x],num-mm[x]);
if(mm[x]<mm[rt])rt=x;
}
void add(int x,int y,int z){
s[x].erase(y);
s[y].erase(x);
s[x].insert(z);
s[z].insert(x);
s[y].insert(z);
s[z].insert(y);
}
void solve(int x,int fa){
// cout<<x<<" "<<fa<<" "<<nw<<endl;
if(sz[x]==1){
s[x].insert(nw);
s[nw].insert(x);
return;
}
vis[fa]=1;
rt=0;
num=sz[x];
fr(x,fa);
fr(rt,0);
vector<pair<int,int> > p(s[rt].size());
int num=0;
for(auto j:s[rt]){
if(!vis[j]){
p[num++]=make_pair(sz[j],j);
}
}
sort(p.begin(),p.begin()+num);
for(int i=0;i<num;i+=2){
if(i+1==num){
int u=p[i].second;
int tmp=Query(nw-1,u-1,rt-1)+1;
if(tmp==nw)add(rt,u,nw);
else if(tmp==u)solve(u,rt);
else{
s[rt].insert(nw);
s[nw].insert(rt);
}
return;
}
else{
int u=p[i].second,v=p[i+1].second;
// cout<<"a "<<u<<" "<<v<<" "<<nw<<endl;
int tmp=Query(nw-1,u-1,v-1)+1;
if(tmp==nw){
tmp=Query(nw-1,u-1,rt-1)+1;
if(tmp==nw)add(rt,u,nw);
else add(rt,v,nw);
return;
}
else if(tmp==u){
solve(u,rt);
return;
}
else if(tmp==v){
solve(v,rt);
return;
}
}
}
s[rt].insert(nw);
s[nw].insert(rt);
return;
}
void Solve(int N) {
s[2].insert(1);
s[1].insert(2);
mm[0]=0x3f3f3f3f;
for(int i=3;i<=N;i++){
nw=i;
for(int j=1;j<=N;j++)vis[j]=0;
sz[1]=i-1;
solve(1,0);
}
for(int i=1;i<=N;i++){
for(auto j:s[i]){
if(j>i)Bridge(i-1,j-1);
}
}
return;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 7
Accepted
time: 0ms
memory: 4032kb
input:
3 0 2 0 1
output:
Accepted: 1
result:
ok 1 move(s)
Test #2:
score: 7
Accepted
time: 0ms
memory: 4032kb
input:
4 1 2 0 2 0 3
output:
Accepted: 2
result:
ok 2 move(s)
Test #3:
score: 7
Accepted
time: 1ms
memory: 3956kb
input:
4 0 3 2 3 0 1
output:
Accepted: 3
result:
ok 3 move(s)
Test #4:
score: 7
Accepted
time: 0ms
memory: 4220kb
input:
5 2 4 2 3 0 2 1 3
output:
Accepted: 4
result:
ok 4 move(s)
Test #5:
score: 7
Accepted
time: 0ms
memory: 4184kb
input:
5 3 4 0 1 0 2 0 3
output:
Accepted: 4
result:
ok 4 move(s)
Test #6:
score: 0
Wrong Answer
time: 0ms
memory: 4020kb
input:
6 1 5 2 4 0 4 1 3 3 4
output:
Wrong Answer [4]
result:
wrong answer
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%