QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#444972#8581. 섬Dimash0 150ms185188kbC++202.2kb2024-06-15 22:44:582024-06-15 22:45:10

Judging History

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

  • [2024-06-15 22:45:10]
  • 评测
  • 测评结果:0
  • 用时:150ms
  • 内存:185188kb
  • [2024-06-15 22:44:58]
  • 提交

answer

#include "island.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 12;
set<int> g[maxn];
int s[maxn];
void add(int x,int y){
    // cout << x << ' ' << y << '\n';
    s[x]++;
    s[y]++;
    g[x].insert(y);
    g[y].insert(x);
}
void construct_two_trees(int N, std::vector<int> U, std::vector<int> V){
    set<pair<int,int>> deg;
    for(int i = 1;i < N;i++){
        add(i,i-1);
    }
    add(0,N-1);
    for(int i = 0;i < N - 3;i++){
        add(U[i],V[i]);
        int x = min(V[i],U[i]),y = max(V[i],U[i]);
        if(y - x == 2){
            int d = add_vertex(x,y,y-1);
            add(d,x);
            add(d,y);
            add(d,y-1);
            break;
        }else if((x == 0 && y == N - 2) || (x == 1 && y == N - 1)){
            int z;
            if(!x){
                z = y + 1;
            }else{
                z = x - 1;
            }
            int d = add_vertex(x,y,z);
            add(d,x);
            add(d,y);
            add(d,z);
            break;
        }
    }
    if(N == 3){
        int d = add_vertex(0,1,2);
        add(d,0);add(d,1);add(d,2);
    }
    N++;
    for(int i = 0;i < N;i++){
        deg.insert({s[i],i});
    }
    vector<array<int,2>> t,t1;
    while(deg.size()){
        auto [col,v] = (*deg.begin());
        if(col != 2) break;
        deg.erase(deg.begin());
        int x = (*g[v].begin()),y = (*g[v].rbegin());
        auto del = [&](int e,int f){
            deg.erase({s[f],f});
            s[f]--;
            g[f].erase(e);
            deg.insert({s[f],f});
        };
        t.push_back({v,x});
        t1.push_back({v,y});
        del(v,x);
        del(v,y);
    }
    // assert((int)deg.size() == 4);
    vector<array<int,2>> edges;
    for(auto [d,v]:deg){
        for(auto [d1,v1]:deg){
            if(v1 > v){
                // cout << v << ' ' << v1 << '\n';
                edges.push_back({v,v1});
            }
        }
    }
    t.push_back(edges[0]);
    t.push_back(edges[1]);
    t1.push_back(edges[5]);
    t1.push_back(edges[2]);
    t1.push_back(edges[3]);
    t.push_back(edges[4]);
    // assert((int)t.size() == (int)t1.size());
    report(t);
    report(t1);
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 6
Accepted
time: 8ms
memory: 52148kb

input:

4
0 2

output:

1
4
3 0
0 1
0 2
1 4
2
4
3 2
2 4
0 4
1 2
1
0 2 1

result:

ok Correct

Test #2:

score: 6
Accepted
time: 8ms
memory: 50920kb

input:

3

output:

1
3
0 1
0 2
1 3
2
3
2 3
0 3
1 2
1
0 1 2

result:

ok Correct

Test #3:

score: 6
Accepted
time: 13ms
memory: 51904kb

input:

4
3 1

output:

1
4
0 1
1 2
1 3
2 4
2
4
0 3
3 4
1 4
2 3
1
1 3 2

result:

ok Correct

Test #4:

score: 0
Wrong Answer
time: 10ms
memory: 51460kb

input:

5
1 4
1 3

output:

1
4
2 1
3 5
3 4
0 5
2
4
2 3
0 4
0 3
0 1
1
1 4 0

result:

wrong answer Wrong Answer, wrong number of edges in the tree

Subtask #2:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 3ms
memory: 51492kb

input:

10
7 0
7 5
7 3
7 1
7 9
7 4
7 2

output:

1
4
1 0
2 3
2 4
2 6
2
4
1 2
2 10
2 8
2 9
1
5 7 6

result:

wrong answer Wrong Answer, wrong number of edges in the tree

Subtask #3:

score: 0
Wrong Answer

Test #10:

score: 0
Wrong Answer
time: 150ms
memory: 185188kb

input:

5000
4593 3389
4593 1610
4593 2357
4593 3323
4593 2037
4593 3667
4593 2737
4593 2642
4593 3981
4593 2700
4593 2134
4593 1719
4593 1444
4593 3729
4593 1371
4593 546
4593 1249
4593 646
4593 4221
4593 1542
4593 2314
4735 4952
4593 680
4593 2555
4593 2152
4593 740
4593 4056
4593 64
4593 3079
4593 3021
4...

output:

1
4
0 1
1 2
1 3
1 7
2
4
0 4999
1 8
1 4
1 5
1
4591 4593 4592

result:

wrong answer Wrong Answer, wrong number of edges in the tree

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%