Submission #1014981

# Submission time Handle Problem Language Result Execution time Memory
1014981 2024-07-05T21:36:15 Z LeonidCuk Village (BOI20_village) C++17
50 / 100
64 ms 15780 KB
#include <bits/stdc++.h>
using namespace std;
vector<int>g[100000],sz(100000),vmin(100000),vmax(100000),temp,temp1;
int n;
long long int resmax=0,resmin=0;
void dfsmax(int a,int b,int c)
{
    if(c==0)
        {
            temp.push_back(a);
        }
        else if(c==2)
        {
            temp1.push_back(a);
        }
    for(auto i:g[a])
    {
        if(i!=b&&c==1)
        {
            dfsmax(i,a,c);
            resmax+=(2*min(sz[i],n-sz[i]));
        }
        else if(i!=b)
        {
            dfsmax(i,a,c);
        }
    }

}
void dfsmin(int a,int b)
{
    for(auto i:g[a])
    {
        if(i!=b)
        {
            dfsmin(i,a);
            if(vmin[i]==i)
            {
                swap(vmin[i],vmin[a]);
                resmin+=2;
            }
        }
    }
}
void dfs(int a,int b)
{
    sz[a]=1;
    for(auto i:g[a])
    {
        if(i!=b)
        {
            dfs(i,a);
            sz[a]+=sz[i];
        }
    }
}
int findcen(int a)
{
    int b=a;
    while(true)
    {
        bool check=true;
        for(auto i:g[a])
        {
            if(i!=b&&sz[i]*2>n)
            {
                b=a;
                a=i;
                check=false;
                break;
            }
        }
        if(check)
        {
            break;
        }
    }
    return a;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a,b;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        vmax[i]=i;
        vmin[i]=i;
    }
    for(int i=0;i<n-1;i++)
    {
        cin>>a>>b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(0,0);
    int cen=findcen(0);
    dfs(cen,cen);
    a=-1;b=-1;
    dfsmin(cen,cen);
    dfsmax(cen,cen,1);
    for(auto i:g[cen])
    {
        if(sz[i]>b)
        {
            b=sz[i];
            a=i;
        }
    }
    dfsmax(a,cen,0);
    for(auto i:g[cen])
    {
        if(i!=a)
        {
           dfsmax(i,cen,2);
        }
    }
    if(temp.size()>temp1.size())temp1.push_back(cen);
    else{temp.push_back(cen);}
    for(int i=0;i<min(temp.size(),temp1.size());i++)
    {
        vmax[temp1[i]]=temp[i];
        vmax[temp[i]]=temp1[i];
    }
    if(vmax[cen]==cen)
    {
        vmax[cen]=vmax[g[cen][0]];
        vmax[g[cen][0]]=cen;
    }
    if(vmin[cen]==cen)
    {
        swap(vmin[cen],vmin[g[cen][0]]);
        resmin+=2;
    }
    cout<<resmin<<" "<<resmax<<"\n";
    for(int i=0;i<n;i++)
    {
        cout<<vmin[i]+1<<" ";
    }
    cout<<"\n";
    for(int i=0;i<n;i++)
    {
        cout<<vmax[i]+1<<" ";
    }
    return 0;
}

Compilation message

Village.cpp: In function 'int main()':
Village.cpp:122:18: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
  122 |     for(int i=0;i<min(temp.size(),temp1.size());i++)
      |                 ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3932 KB Output is correct
2 Correct 2 ms 3992 KB Output is correct
3 Correct 2 ms 4188 KB Output is correct
4 Correct 2 ms 3932 KB Output is correct
5 Correct 2 ms 3932 KB Output is correct
6 Correct 2 ms 3932 KB Output is correct
7 Partially correct 2 ms 3932 KB Partially correct
8 Correct 2 ms 3932 KB Output is correct
9 Correct 2 ms 3928 KB Output is correct
10 Correct 2 ms 3932 KB Output is correct
11 Correct 2 ms 3932 KB Output is correct
12 Correct 2 ms 3932 KB Output is correct
13 Correct 2 ms 3932 KB Output is correct
14 Partially correct 2 ms 4000 KB Partially correct
15 Correct 2 ms 3932 KB Output is correct
16 Partially correct 2 ms 3932 KB Partially correct
17 Correct 2 ms 3932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 2 ms 3932 KB Partially correct
2 Partially correct 2 ms 3932 KB Partially correct
3 Partially correct 2 ms 3932 KB Partially correct
4 Partially correct 3 ms 3932 KB Partially correct
5 Partially correct 2 ms 3928 KB Partially correct
6 Partially correct 3 ms 3932 KB Partially correct
7 Correct 2 ms 3932 KB Output is correct
8 Partially correct 2 ms 3932 KB Partially correct
9 Partially correct 3 ms 3932 KB Partially correct
10 Correct 2 ms 3932 KB Output is correct
11 Correct 2 ms 3932 KB Output is correct
12 Partially correct 2 ms 3932 KB Partially correct
13 Correct 3 ms 3928 KB Output is correct
14 Partially correct 2 ms 3932 KB Partially correct
15 Partially correct 4 ms 3932 KB Partially correct
16 Partially correct 2 ms 3932 KB Partially correct
17 Partially correct 2 ms 3932 KB Partially correct
18 Partially correct 2 ms 3932 KB Partially correct
19 Partially correct 2 ms 3932 KB Partially correct
20 Partially correct 2 ms 3932 KB Partially correct
21 Partially correct 2 ms 3932 KB Partially correct
22 Partially correct 3 ms 3932 KB Partially correct
23 Partially correct 4 ms 3928 KB Partially correct
24 Partially correct 2 ms 3932 KB Partially correct
25 Correct 2 ms 3932 KB Output is correct
26 Partially correct 2 ms 3932 KB Partially correct
27 Correct 3 ms 3996 KB Output is correct
28 Partially correct 2 ms 3932 KB Partially correct
29 Partially correct 2 ms 3932 KB Partially correct
30 Partially correct 2 ms 3932 KB Partially correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3932 KB Output is correct
2 Correct 2 ms 3992 KB Output is correct
3 Correct 2 ms 4188 KB Output is correct
4 Correct 2 ms 3932 KB Output is correct
5 Correct 2 ms 3932 KB Output is correct
6 Correct 2 ms 3932 KB Output is correct
7 Partially correct 2 ms 3932 KB Partially correct
8 Correct 2 ms 3932 KB Output is correct
9 Correct 2 ms 3928 KB Output is correct
10 Correct 2 ms 3932 KB Output is correct
11 Correct 2 ms 3932 KB Output is correct
12 Correct 2 ms 3932 KB Output is correct
13 Correct 2 ms 3932 KB Output is correct
14 Partially correct 2 ms 4000 KB Partially correct
15 Correct 2 ms 3932 KB Output is correct
16 Partially correct 2 ms 3932 KB Partially correct
17 Correct 2 ms 3932 KB Output is correct
18 Partially correct 2 ms 3932 KB Partially correct
19 Partially correct 2 ms 3932 KB Partially correct
20 Partially correct 2 ms 3932 KB Partially correct
21 Partially correct 3 ms 3932 KB Partially correct
22 Partially correct 2 ms 3928 KB Partially correct
23 Partially correct 3 ms 3932 KB Partially correct
24 Correct 2 ms 3932 KB Output is correct
25 Partially correct 2 ms 3932 KB Partially correct
26 Partially correct 3 ms 3932 KB Partially correct
27 Correct 2 ms 3932 KB Output is correct
28 Correct 2 ms 3932 KB Output is correct
29 Partially correct 2 ms 3932 KB Partially correct
30 Correct 3 ms 3928 KB Output is correct
31 Partially correct 2 ms 3932 KB Partially correct
32 Partially correct 4 ms 3932 KB Partially correct
33 Partially correct 2 ms 3932 KB Partially correct
34 Partially correct 2 ms 3932 KB Partially correct
35 Partially correct 2 ms 3932 KB Partially correct
36 Partially correct 2 ms 3932 KB Partially correct
37 Partially correct 2 ms 3932 KB Partially correct
38 Partially correct 2 ms 3932 KB Partially correct
39 Partially correct 3 ms 3932 KB Partially correct
40 Partially correct 4 ms 3928 KB Partially correct
41 Partially correct 2 ms 3932 KB Partially correct
42 Correct 2 ms 3932 KB Output is correct
43 Partially correct 2 ms 3932 KB Partially correct
44 Correct 3 ms 3996 KB Output is correct
45 Partially correct 2 ms 3932 KB Partially correct
46 Partially correct 2 ms 3932 KB Partially correct
47 Partially correct 2 ms 3932 KB Partially correct
48 Partially correct 54 ms 9548 KB Partially correct
49 Partially correct 53 ms 9884 KB Partially correct
50 Partially correct 57 ms 10068 KB Partially correct
51 Partially correct 37 ms 8660 KB Partially correct
52 Partially correct 45 ms 10004 KB Partially correct
53 Partially correct 48 ms 9552 KB Partially correct
54 Correct 31 ms 9808 KB Output is correct
55 Correct 64 ms 15780 KB Output is correct
56 Correct 58 ms 12628 KB Output is correct
57 Partially correct 57 ms 11860 KB Partially correct
58 Correct 63 ms 10836 KB Output is correct
59 Partially correct 50 ms 10068 KB Partially correct
60 Partially correct 33 ms 10064 KB Partially correct
61 Partially correct 36 ms 10184 KB Partially correct
62 Partially correct 45 ms 10320 KB Partially correct
63 Partially correct 31 ms 9908 KB Partially correct
64 Partially correct 41 ms 10272 KB Partially correct
65 Partially correct 42 ms 10320 KB Partially correct
66 Partially correct 35 ms 9956 KB Partially correct
67 Partially correct 28 ms 8908 KB Partially correct
68 Partially correct 32 ms 9496 KB Partially correct
69 Partially correct 46 ms 10316 KB Partially correct
70 Partially correct 34 ms 9940 KB Partially correct
71 Partially correct 28 ms 8396 KB Partially correct
72 Partially correct 30 ms 8952 KB Partially correct
73 Partially correct 47 ms 10436 KB Partially correct
74 Partially correct 33 ms 9928 KB Partially correct
75 Partially correct 49 ms 9792 KB Partially correct
76 Partially correct 48 ms 9808 KB Partially correct
77 Partially correct 37 ms 10060 KB Partially correct
78 Partially correct 30 ms 8140 KB Partially correct
79 Partially correct 33 ms 8620 KB Partially correct
80 Partially correct 45 ms 9812 KB Partially correct
81 Partially correct 45 ms 10184 KB Partially correct
82 Partially correct 38 ms 10256 KB Partially correct