QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#747318#63. MeetingsShumomo7 1ms4268kbC++142.5kb2024-11-14 16:52:452024-11-14 16:52:46

Judging History

你现在查看的是最新测评结果

  • [2024-11-14 16:52:46]
  • 评测
  • 测评结果:7
  • 用时:1ms
  • 内存:4268kb
  • [2024-11-14 16:52:45]
  • 提交

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 if(tmp==rt){
                s[rt].insert(nw);
                s[nw].insert(rt);
            }
            else{
                add(rt,u,tmp);
                s[tmp].insert(nw);
                s[nw].insert(tmp);
            }
            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++){
        if(s[i].empty()){
            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: 7
Accepted

Test #1:

score: 7
Accepted
time: 1ms
memory: 4220kb

input:

3
0 2
0 1

output:

Accepted: 1

result:

ok 1 move(s)

Test #2:

score: 7
Accepted
time: 0ms
memory: 3952kb

input:

4
1 2
0 2
0 3

output:

Accepted: 2

result:

ok 2 move(s)

Test #3:

score: 7
Accepted
time: 0ms
memory: 4264kb

input:

4
0 3
2 3
0 1

output:

Accepted: 3

result:

ok 3 move(s)

Test #4:

score: 7
Accepted
time: 0ms
memory: 3932kb

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: 3976kb

input:

5
3 4
0 1
0 2
0 3

output:

Accepted: 4

result:

ok 4 move(s)

Test #6:

score: 7
Accepted
time: 0ms
memory: 3972kb

input:

6
1 5
2 4
0 4
1 3
3 4

output:

Accepted: 6

result:

ok 6 move(s)

Test #7:

score: 7
Accepted
time: 0ms
memory: 4000kb

input:

6
2 4
0 1
0 2
0 5
3 4

output:

Accepted: 6

result:

ok 6 move(s)

Test #8:

score: 7
Accepted
time: 0ms
memory: 3908kb

input:

7
1 4
0 6
0 5
1 2
0 3
0 4

output:

Accepted: 8

result:

ok 8 move(s)

Test #9:

score: 7
Accepted
time: 0ms
memory: 3908kb

input:

7
0 4
1 4
2 3
2 4
0 6
2 5

output:

Accepted: 7

result:

ok 7 move(s)

Test #10:

score: 7
Accepted
time: 0ms
memory: 3972kb

input:

7
3 5
4 5
0 2
2 6
1 2
1 5

output:

Accepted: 6

result:

ok 6 move(s)

Test #11:

score: 7
Accepted
time: 0ms
memory: 4268kb

input:

7
3 6
5 6
4 6
1 6
2 6
0 6

output:

Accepted: 8

result:

ok 8 move(s)

Test #12:

score: 7
Accepted
time: 0ms
memory: 3936kb

input:

7
2 3
0 5
4 6
1 6
0 2
3 4

output:

Accepted: 10

result:

ok 10 move(s)

Test #13:

score: 7
Accepted
time: 0ms
memory: 3964kb

input:

7
5 6
1 2
4 5
2 3
3 4
0 1

output:

Accepted: 8

result:

ok 8 move(s)

Subtask #2:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #14:

score: 0
Wrong Answer
time: 1ms
memory: 4260kb

input:

50
25 32
16 48
36 46
13 48
18 27
18 30
9 29
19 47
30 35
2 36
1 49
33 34
41 47
11 13
7 10
17 38
2 18
1 15
1 33
4 23
8 11
36 47
14 20
25 39
5 7
12 48
2 45
21 47
0 21
1 23
19 43
32 33
4 14
22 36
38 46
5 28
1 29
2 31
3 4
40 47
34 44
34 42
24 43
33 36
11 26
6 11
7 47
37 38
1 6

output:

Wrong Answer [4]

result:

wrong answer 

Subtask #3:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%