답안 #971389

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
971389 2024-04-28T12:49:12 Z maxFedorchuk Village (BOI20_village) C++17
100 / 100
74 ms 22304 KB
#include <bits/stdc++.h> ///sadkj;;basdbfalsdfhblkabsjfbasdkjfbksabfkdsjbfalkbflkablksdbfkjablkfbaslkfdb
using namespace std;
#define LCBorz ios_base::sync_with_stdio(false); cin.tie(0);
#define int long long
#define all(x) x.begin(), x.end()
#define endl '\n'
const int N=200005;
const int INF=1e18;
int n,mn=0,mx=0,total=0;
vector<int> adj[N],v(N),v1(N),sz(N,1);
vector<int> rec;
void dfs(int k,int pa){
  for(int j:adj[k]){
    if(j==pa)continue;
    dfs(j,k);
    if(v[j]==j){
      swap(v[j],v[k]);
      mn+=2;
    }
    sz[k]+=sz[j];
  }
}
int cen(int k,int pa){
  for(int j:adj[k]){
    if(j==pa)continue;
    if(sz[j]>n/2){
      return cen(j,k);
    }
  }
  return k;
}
void dfs1(int k,int pa,int deep){
  total+=deep*2;
  rec.push_back(k);
  for(int j:adj[k]){
    if(j==pa)continue;
    dfs1(j,k,deep+1);
  }
}
int32_t main() {
  LCBorz;
  cin>>n;
  for(int i=1;i<n;i++){
    int a,b;cin>>a>>b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  iota(all(v),0);
  dfs(1,1);
  if(v[1]==1){
    swap(v[1],v[adj[1][0]]);
    mn+=2;
  }
  int c=cen(1,1);
  dfs1(c,c,0);
  mx=total;
  for(int i=0;i<n;i++){
    v1[rec[(i+n/2)%n]]=rec[i];
  }
  cout<<mn<<' '<<mx<<endl;
  for(int i=1;i<=n;i++){
    cout<<v[i]<<' ';
  }
  cout<<endl;
  for(int i=1;i<=n;i++){
    cout<<v1[i]<<' ';
  }
  cout<<endl;
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 9816 KB Output is correct
2 Correct 3 ms 9820 KB Output is correct
3 Correct 4 ms 9816 KB Output is correct
4 Correct 3 ms 9820 KB Output is correct
5 Correct 3 ms 9644 KB Output is correct
6 Correct 3 ms 9816 KB Output is correct
7 Correct 4 ms 9820 KB Output is correct
8 Correct 3 ms 9828 KB Output is correct
9 Correct 4 ms 9820 KB Output is correct
10 Correct 3 ms 9820 KB Output is correct
11 Correct 4 ms 9820 KB Output is correct
12 Correct 3 ms 9816 KB Output is correct
13 Correct 3 ms 9844 KB Output is correct
14 Correct 3 ms 9868 KB Output is correct
15 Correct 3 ms 9820 KB Output is correct
16 Correct 3 ms 9872 KB Output is correct
17 Correct 4 ms 9816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9824 KB Output is correct
2 Correct 3 ms 9820 KB Output is correct
3 Correct 4 ms 9820 KB Output is correct
4 Correct 5 ms 9820 KB Output is correct
5 Correct 4 ms 9872 KB Output is correct
6 Correct 4 ms 9816 KB Output is correct
7 Correct 4 ms 9816 KB Output is correct
8 Correct 4 ms 9820 KB Output is correct
9 Correct 4 ms 9820 KB Output is correct
10 Correct 4 ms 9820 KB Output is correct
11 Correct 4 ms 9816 KB Output is correct
12 Correct 4 ms 9816 KB Output is correct
13 Correct 4 ms 10072 KB Output is correct
14 Correct 4 ms 10072 KB Output is correct
15 Correct 6 ms 9820 KB Output is correct
16 Correct 4 ms 9820 KB Output is correct
17 Correct 4 ms 9820 KB Output is correct
18 Correct 4 ms 9816 KB Output is correct
19 Correct 3 ms 9820 KB Output is correct
20 Correct 4 ms 9820 KB Output is correct
21 Correct 4 ms 9816 KB Output is correct
22 Correct 4 ms 9820 KB Output is correct
23 Correct 4 ms 9820 KB Output is correct
24 Correct 4 ms 9820 KB Output is correct
25 Correct 4 ms 9820 KB Output is correct
26 Correct 4 ms 9820 KB Output is correct
27 Correct 3 ms 9820 KB Output is correct
28 Correct 4 ms 9816 KB Output is correct
29 Correct 4 ms 9820 KB Output is correct
30 Correct 4 ms 9820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 9816 KB Output is correct
2 Correct 3 ms 9820 KB Output is correct
3 Correct 4 ms 9816 KB Output is correct
4 Correct 3 ms 9820 KB Output is correct
5 Correct 3 ms 9644 KB Output is correct
6 Correct 3 ms 9816 KB Output is correct
7 Correct 4 ms 9820 KB Output is correct
8 Correct 3 ms 9828 KB Output is correct
9 Correct 4 ms 9820 KB Output is correct
10 Correct 3 ms 9820 KB Output is correct
11 Correct 4 ms 9820 KB Output is correct
12 Correct 3 ms 9816 KB Output is correct
13 Correct 3 ms 9844 KB Output is correct
14 Correct 3 ms 9868 KB Output is correct
15 Correct 3 ms 9820 KB Output is correct
16 Correct 3 ms 9872 KB Output is correct
17 Correct 4 ms 9816 KB Output is correct
18 Correct 4 ms 9824 KB Output is correct
19 Correct 3 ms 9820 KB Output is correct
20 Correct 4 ms 9820 KB Output is correct
21 Correct 5 ms 9820 KB Output is correct
22 Correct 4 ms 9872 KB Output is correct
23 Correct 4 ms 9816 KB Output is correct
24 Correct 4 ms 9816 KB Output is correct
25 Correct 4 ms 9820 KB Output is correct
26 Correct 4 ms 9820 KB Output is correct
27 Correct 4 ms 9820 KB Output is correct
28 Correct 4 ms 9816 KB Output is correct
29 Correct 4 ms 9816 KB Output is correct
30 Correct 4 ms 10072 KB Output is correct
31 Correct 4 ms 10072 KB Output is correct
32 Correct 6 ms 9820 KB Output is correct
33 Correct 4 ms 9820 KB Output is correct
34 Correct 4 ms 9820 KB Output is correct
35 Correct 4 ms 9816 KB Output is correct
36 Correct 3 ms 9820 KB Output is correct
37 Correct 4 ms 9820 KB Output is correct
38 Correct 4 ms 9816 KB Output is correct
39 Correct 4 ms 9820 KB Output is correct
40 Correct 4 ms 9820 KB Output is correct
41 Correct 4 ms 9820 KB Output is correct
42 Correct 4 ms 9820 KB Output is correct
43 Correct 4 ms 9820 KB Output is correct
44 Correct 3 ms 9820 KB Output is correct
45 Correct 4 ms 9816 KB Output is correct
46 Correct 4 ms 9820 KB Output is correct
47 Correct 4 ms 9820 KB Output is correct
48 Correct 39 ms 15996 KB Output is correct
49 Correct 45 ms 16808 KB Output is correct
50 Correct 46 ms 16836 KB Output is correct
51 Correct 35 ms 15312 KB Output is correct
52 Correct 43 ms 16584 KB Output is correct
53 Correct 42 ms 16072 KB Output is correct
54 Correct 26 ms 15820 KB Output is correct
55 Correct 74 ms 22304 KB Output is correct
56 Correct 50 ms 19408 KB Output is correct
57 Correct 48 ms 18376 KB Output is correct
58 Correct 49 ms 17608 KB Output is correct
59 Correct 44 ms 16912 KB Output is correct
60 Correct 35 ms 16772 KB Output is correct
61 Correct 36 ms 16828 KB Output is correct
62 Correct 43 ms 17208 KB Output is correct
63 Correct 41 ms 16584 KB Output is correct
64 Correct 41 ms 17092 KB Output is correct
65 Correct 42 ms 17352 KB Output is correct
66 Correct 43 ms 16584 KB Output is correct
67 Correct 29 ms 15300 KB Output is correct
68 Correct 33 ms 16072 KB Output is correct
69 Correct 40 ms 17604 KB Output is correct
70 Correct 39 ms 16748 KB Output is correct
71 Correct 28 ms 15048 KB Output is correct
72 Correct 29 ms 15568 KB Output is correct
73 Correct 41 ms 17316 KB Output is correct
74 Correct 36 ms 16812 KB Output is correct
75 Correct 47 ms 17296 KB Output is correct
76 Correct 41 ms 16584 KB Output is correct
77 Correct 44 ms 17136 KB Output is correct
78 Correct 30 ms 14532 KB Output is correct
79 Correct 32 ms 15304 KB Output is correct
80 Correct 45 ms 17284 KB Output is correct
81 Correct 40 ms 17336 KB Output is correct
82 Correct 36 ms 16840 KB Output is correct