답안 #1048180

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1048180 2024-08-08T04:13:57 Z 12345678 Village (BOI20_village) C++17
6 / 100
2 ms 6748 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

const int nx=1e5+5;

int n, u, v, sz[nx], rt, res, mn[nx], mx[nx], x, lst, l, r, st, cur;
vector<int> d[nx], g[nx];

int dfssz(int u, int p)
{
    sz[u]=1;
    for (auto v:d[u]) if (v!=p) sz[u]+=dfssz(v, u);
    return sz[u];
}

int findcentroid(int u, int p, int rtsz)
{
    for (auto v:d[u]) if (v!=p&&2*sz[v]>rtsz) return findcentroid(v, u, rtsz);
    return u;
}

void dfsadd(int u, int p, int t, int lvl)
{
    g[t].push_back(u);
    res+=2*(lvl+1);
    for (auto v:d[u]) if (v!=p) dfsadd(v, u, t, lvl+1);
}

int32_t main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n;
    for (int i=1; i<n; i++) cin>>u>>v, d[u].push_back(v), d[v].push_back(u);
    rt=findcentroid(1, 1, dfssz(1, 1));
    dfssz(rt, rt);
    vector<pair<int, int>> s;
    for (auto v:d[rt]) s.push_back({-sz[v], v});
    sort(s.begin(), s.end());
    for (int i=0; i<s.size(); i++) dfsadd(s[i].second, rt, i, 0);
    x=s.size();
    g[x].push_back(rt);
    l=0, r=1, lst=1, st=cur=g[0].back(), g[0].pop_back();
    //cout<<"x "<<x<<'\n';
    //for (int i=0; i<=x; i++) cout<<i<<' '<<g[i].size()<<'\n';
    while (1)
    {
        //cout<<"debug "<<l<<' '<<r<<' '<<cur<<'\n';
        if (g[r].empty())
        {
            if (lst==x)
            {
                mx[cur]=st;
                break;
            }
            else r=++lst;
        }
        //cout<<"debugg "<<l<<' '<<r<<' '<<cur<<'\n';
        mx[cur]=g[r].back();
        cur=g[r].back();
        g[r].pop_back();
        swap(l, r);
    }
    cout<<0<<' '<<res<<'\n';
    for (int i=1; i<=n; i++) cout<<1<<' ';
    cout<<'\n';
    for (int i=1; i<=n; i++) cout<<mx[i]<<' ';
}

Compilation message

Village.cpp: In function 'int32_t main()':
Village.cpp:42:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     for (int i=0; i<s.size(); i++) dfsadd(s[i].second, rt, i, 0);
      |                   ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 6744 KB Partially correct
2 Partially correct 1 ms 6748 KB Partially correct
3 Partially correct 1 ms 6748 KB Partially correct
4 Partially correct 1 ms 6748 KB Partially correct
5 Partially correct 1 ms 6748 KB Partially correct
6 Partially correct 1 ms 6748 KB Partially correct
7 Partially correct 1 ms 6748 KB Partially correct
8 Partially correct 1 ms 6748 KB Partially correct
9 Partially correct 1 ms 6748 KB Partially correct
10 Partially correct 1 ms 6748 KB Partially correct
11 Partially correct 1 ms 6748 KB Partially correct
12 Partially correct 1 ms 6748 KB Partially correct
13 Partially correct 2 ms 6748 KB Partially correct
14 Partially correct 1 ms 6748 KB Partially correct
15 Partially correct 1 ms 6748 KB Partially correct
16 Partially correct 1 ms 6748 KB Partially correct
17 Partially correct 1 ms 6748 KB Partially correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 6748 KB Integer parameter [name=vi] equals to 0, violates the range [1, 256]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 6744 KB Partially correct
2 Partially correct 1 ms 6748 KB Partially correct
3 Partially correct 1 ms 6748 KB Partially correct
4 Partially correct 1 ms 6748 KB Partially correct
5 Partially correct 1 ms 6748 KB Partially correct
6 Partially correct 1 ms 6748 KB Partially correct
7 Partially correct 1 ms 6748 KB Partially correct
8 Partially correct 1 ms 6748 KB Partially correct
9 Partially correct 1 ms 6748 KB Partially correct
10 Partially correct 1 ms 6748 KB Partially correct
11 Partially correct 1 ms 6748 KB Partially correct
12 Partially correct 1 ms 6748 KB Partially correct
13 Partially correct 2 ms 6748 KB Partially correct
14 Partially correct 1 ms 6748 KB Partially correct
15 Partially correct 1 ms 6748 KB Partially correct
16 Partially correct 1 ms 6748 KB Partially correct
17 Partially correct 1 ms 6748 KB Partially correct
18 Incorrect 1 ms 6748 KB Integer parameter [name=vi] equals to 0, violates the range [1, 256]
19 Halted 0 ms 0 KB -