Submission #854164

# Submission time Handle Problem Language Result Execution time Memory
854164 2023-09-26T09:43:55 Z 8pete8 Village (BOI20_village) C++14
50 / 100
78 ms 25276 KB
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
#define int long long
const int mxn=1e5,mod=1000000007,lg=25,root=1000,inf=1e18;
vector<int>adj[mxn+10];
int subsize[mxn+10],n;
int ansmn[mxn+10],ansmx[mxn+10],up[mxn+10][lg+10],h[mxn+10];
vector<int>sub[mxn+10];
int cnt=0;
int ans2=0,ans1=0;
bool cmp(int a,int b){return subsize[a]>subsize[b];}
void build(int cur,int p){
    subsize[cur]=1;
    for(auto i:adj[cur]){
        if(i==p)continue;
        build(i,cur);
        ans2+=min(subsize[i],n-subsize[i]);//we claim we can achive this
        subsize[cur]+=subsize[i];
    }
}
int getcen(int cur,int p){
    for(auto i:adj[cur]){
        if(i==p)continue;
        if(subsize[i]*2>n)return getcen(i,cur);
    }
    return cur;
}
void dfs(int cur,int p){
    sub[cnt].pb(cur);
    for(auto i:adj[cur]){
        if(i==p)continue;
        dfs(i,cur);
    }
}
int solvemn(int cur,int p){
    vector<int>v;
    for(auto i:adj[cur]){
        if(i==p)continue;
        if(solvemn(i,cur))v.pb(i);
    }
    if(v.size()){
        ans1++;
        ansmn[cur]=v[0];
        for(int i=0;i<v.size()-1;i++)ansmn[v[i]]=v[i+1],ans1+=2;
        ansmn[v.back()]=cur;
        ans1++;
    }
    else return 1;
    return 0;
}
void solvemx(){
    int node=getcen(1,-1);
    for(auto i:adj[node])dfs(i,node),cnt++;
    //for(auto i:sub)cout<<i<<"\n";
    sort(all(adj[node]),cmp);
    sub[cnt].pb(node);
    cnt++;
    vector<int>v;
    while(cnt>0){
        for(int i=0;i<cnt;i++){
            v.pb(sub[i].back());
            sub[i].pop_back();
            if(sub[i].size()==0)swap(sub[i],sub[cnt-1]),cnt--;
        }
    }
    for(int i=0;i<v.size()-1;i++)ansmx[v[i]]=v[i+1];
    ansmx[v.back()]=v[0];
}
int32_t main(){
    fastio
    cin>>n;
    for(int i=0;i<n-1;i++){
        int u,v;cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    //fill(ansmn,ansmn+1+n,1);
    //fill(ansmx,ansmx+n+1,1);
    build(1,-1);
    solvemx();
    if(solvemn(1,-1)){
        int node=adj[1][0];
        ansmn[1]=node;
        int next=ansmn[node];
        while(ansmn[next]!=node)next=ansmn[next];
        ansmn[next]=1;
        ans1+=2;
    }
    cout<<ans1<<' '<<ans2*2<<'\n';
    for(int i=1;i<=n;i++)cout<<ansmn[i]<<" ";
    cout<<'\n';
    for(int i=1;i<=n;i++)cout<<ansmx[i]<<" ";
}

Compilation message

Village.cpp: In function 'long long int solvemn(long long int, long long int)':
Village.cpp:70:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |         for(int i=0;i<v.size()-1;i++)ansmn[v[i]]=v[i+1],ans1+=2;
      |                     ~^~~~~~~~~~~
Village.cpp: In function 'void solvemx()':
Village.cpp:92:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |     for(int i=0;i<v.size()-1;i++)ansmx[v[i]]=v[i+1];
      |                 ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 2 ms 10844 KB Output is correct
3 Correct 2 ms 10840 KB Output is correct
4 Partially correct 2 ms 10840 KB Partially correct
5 Correct 3 ms 10840 KB Output is correct
6 Partially correct 2 ms 10840 KB Partially correct
7 Correct 2 ms 10844 KB Output is correct
8 Partially correct 2 ms 10840 KB Partially correct
9 Partially correct 2 ms 10840 KB Partially correct
10 Partially correct 2 ms 10840 KB Partially correct
11 Partially correct 3 ms 10840 KB Partially correct
12 Partially correct 2 ms 10840 KB Partially correct
13 Partially correct 2 ms 10840 KB Partially correct
14 Correct 2 ms 10840 KB Output is correct
15 Partially correct 2 ms 10840 KB Partially correct
16 Partially correct 2 ms 10844 KB Partially correct
17 Correct 2 ms 10840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 2 ms 10840 KB Partially correct
2 Partially correct 2 ms 11096 KB Partially correct
3 Partially correct 2 ms 10840 KB Partially correct
4 Partially correct 2 ms 11100 KB Partially correct
5 Partially correct 2 ms 11100 KB Partially correct
6 Partially correct 2 ms 11096 KB Partially correct
7 Partially correct 2 ms 11100 KB Partially correct
8 Partially correct 2 ms 11096 KB Partially correct
9 Partially correct 2 ms 11100 KB Partially correct
10 Correct 2 ms 11096 KB Output is correct
11 Partially correct 2 ms 11096 KB Partially correct
12 Correct 2 ms 11100 KB Output is correct
13 Partially correct 2 ms 11096 KB Partially correct
14 Partially correct 2 ms 11096 KB Partially correct
15 Partially correct 2 ms 11352 KB Partially correct
16 Correct 2 ms 11100 KB Output is correct
17 Partially correct 2 ms 11096 KB Partially correct
18 Partially correct 2 ms 11096 KB Partially correct
19 Partially correct 2 ms 11096 KB Partially correct
20 Partially correct 2 ms 11100 KB Partially correct
21 Partially correct 2 ms 11096 KB Partially correct
22 Partially correct 3 ms 11104 KB Partially correct
23 Partially correct 2 ms 11096 KB Partially correct
24 Partially correct 2 ms 11100 KB Partially correct
25 Partially correct 3 ms 11100 KB Partially correct
26 Partially correct 3 ms 11096 KB Partially correct
27 Partially correct 2 ms 11096 KB Partially correct
28 Correct 2 ms 11100 KB Output is correct
29 Correct 2 ms 11096 KB Output is correct
30 Partially correct 2 ms 11096 KB Partially correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 2 ms 10844 KB Output is correct
3 Correct 2 ms 10840 KB Output is correct
4 Partially correct 2 ms 10840 KB Partially correct
5 Correct 3 ms 10840 KB Output is correct
6 Partially correct 2 ms 10840 KB Partially correct
7 Correct 2 ms 10844 KB Output is correct
8 Partially correct 2 ms 10840 KB Partially correct
9 Partially correct 2 ms 10840 KB Partially correct
10 Partially correct 2 ms 10840 KB Partially correct
11 Partially correct 3 ms 10840 KB Partially correct
12 Partially correct 2 ms 10840 KB Partially correct
13 Partially correct 2 ms 10840 KB Partially correct
14 Correct 2 ms 10840 KB Output is correct
15 Partially correct 2 ms 10840 KB Partially correct
16 Partially correct 2 ms 10844 KB Partially correct
17 Correct 2 ms 10840 KB Output is correct
18 Partially correct 2 ms 10840 KB Partially correct
19 Partially correct 2 ms 11096 KB Partially correct
20 Partially correct 2 ms 10840 KB Partially correct
21 Partially correct 2 ms 11100 KB Partially correct
22 Partially correct 2 ms 11100 KB Partially correct
23 Partially correct 2 ms 11096 KB Partially correct
24 Partially correct 2 ms 11100 KB Partially correct
25 Partially correct 2 ms 11096 KB Partially correct
26 Partially correct 2 ms 11100 KB Partially correct
27 Correct 2 ms 11096 KB Output is correct
28 Partially correct 2 ms 11096 KB Partially correct
29 Correct 2 ms 11100 KB Output is correct
30 Partially correct 2 ms 11096 KB Partially correct
31 Partially correct 2 ms 11096 KB Partially correct
32 Partially correct 2 ms 11352 KB Partially correct
33 Correct 2 ms 11100 KB Output is correct
34 Partially correct 2 ms 11096 KB Partially correct
35 Partially correct 2 ms 11096 KB Partially correct
36 Partially correct 2 ms 11096 KB Partially correct
37 Partially correct 2 ms 11100 KB Partially correct
38 Partially correct 2 ms 11096 KB Partially correct
39 Partially correct 3 ms 11104 KB Partially correct
40 Partially correct 2 ms 11096 KB Partially correct
41 Partially correct 2 ms 11100 KB Partially correct
42 Partially correct 3 ms 11100 KB Partially correct
43 Partially correct 3 ms 11096 KB Partially correct
44 Partially correct 2 ms 11096 KB Partially correct
45 Correct 2 ms 11100 KB Output is correct
46 Correct 2 ms 11096 KB Output is correct
47 Partially correct 2 ms 11096 KB Partially correct
48 Partially correct 41 ms 16264 KB Partially correct
49 Partially correct 55 ms 17400 KB Partially correct
50 Partially correct 45 ms 16960 KB Partially correct
51 Partially correct 35 ms 15652 KB Partially correct
52 Partially correct 42 ms 16876 KB Partially correct
53 Partially correct 49 ms 16332 KB Partially correct
54 Partially correct 26 ms 17728 KB Partially correct
55 Partially correct 78 ms 25276 KB Partially correct
56 Partially correct 55 ms 20932 KB Partially correct
57 Partially correct 60 ms 19652 KB Partially correct
58 Partially correct 49 ms 18296 KB Partially correct
59 Partially correct 45 ms 17088 KB Partially correct
60 Correct 45 ms 19764 KB Output is correct
61 Partially correct 37 ms 17836 KB Partially correct
62 Partially correct 41 ms 17176 KB Partially correct
63 Partially correct 35 ms 16932 KB Partially correct
64 Partially correct 54 ms 17452 KB Partially correct
65 Partially correct 39 ms 17464 KB Partially correct
66 Partially correct 34 ms 16884 KB Partially correct
67 Partially correct 29 ms 16020 KB Partially correct
68 Partially correct 31 ms 16492 KB Partially correct
69 Partially correct 45 ms 17856 KB Partially correct
70 Partially correct 33 ms 16996 KB Partially correct
71 Partially correct 25 ms 15464 KB Partially correct
72 Partially correct 29 ms 16120 KB Partially correct
73 Partially correct 40 ms 17416 KB Partially correct
74 Partially correct 35 ms 17048 KB Partially correct
75 Partially correct 45 ms 17208 KB Partially correct
76 Partially correct 45 ms 17076 KB Partially correct
77 Partially correct 40 ms 17316 KB Partially correct
78 Partially correct 27 ms 15288 KB Partially correct
79 Partially correct 32 ms 15652 KB Partially correct
80 Partially correct 48 ms 17580 KB Partially correct
81 Partially correct 42 ms 17380 KB Partially correct
82 Correct 35 ms 17088 KB Output is correct