Submission #478384

# Submission time Handle Problem Language Result Execution time Memory
478384 2021-10-07T06:52:46 Z pluto_ish Village (BOI20_village) C++14
50 / 100
94 ms 19164 KB
#include <bits/stdc++.h>
 
#define pb push_back
#define ff first
#define ss second
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = (ll)1<<62;
const ll MOD = 1e9+7;
const int iINF = 1<<30;
const double PI = 3.14159265359;

int ans;
vector<int> to, revto;
vector<vector<int> > adj;

int dfs(int u, int p){
  vector<int> tmp;
  for(int v : adj[u]){
    if(v == p) continue;

    int x = dfs(v, u);
    if(x != -1) tmp.pb(x);
  }

  tmp.pb(u);
  if(tmp.size() > 1){
    for(int i=0;i+1<(int)tmp.size();i+=2){
      to[tmp[i]] = revto[tmp[i]] = tmp[i+1];
      to[tmp[i+1]] = revto[tmp[i+1]] = tmp[i];
    }
    if(tmp.size()%2){
      to[tmp.back()] = tmp[1];
      to[tmp[0]] = tmp.back();

      revto[tmp[1]] = tmp.back();
      revto[tmp.back()] = tmp[0];
    }
    if(u != 0) ans -= 2;
    return -1;
  }
  else return u;
}  

void solve(){
  int n;
  cin >> n;
  assert(n != 1);
  adj.assign(n, vector<int>());
  for(int i=0;i<n-1;i++){
    int u, v;
    cin >> u >> v;
    u--; v--;
    adj[u].pb(v); adj[v].pb(u);
  }  
  adj[0].pb(0);
  
  to.assign(n, -1); revto.assign(n, -1);
  ans = 2*(n-1);
  int x = dfs(0, 0);
  if(x != -1){
    ans += 2;
    //cout << x+1 << " " << adj[x][0]+1 << " " << to[adj[x][0]]+1 << "\n";
    to[x] = adj[x][0];
    to[revto[adj[x][0]]] = x;
  }
  
  cout << ans << " " << 1 << "\n";
  for(int v : to) cout << v+1 << " ";
  cout << "\n";
  for(int i=0;i<n;i++) cout << 1 << " ";
  cout << "\n";
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int t = 1;
  //cin >> t;
  while(t--){
    solve();
  }  
  
  return 0;
}  
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 204 KB Partially correct
2 Partially correct 1 ms 208 KB Partially correct
3 Partially correct 0 ms 208 KB Partially correct
4 Partially correct 0 ms 208 KB Partially correct
5 Partially correct 1 ms 208 KB Partially correct
6 Partially correct 1 ms 208 KB Partially correct
7 Partially correct 0 ms 208 KB Partially correct
8 Partially correct 1 ms 316 KB Partially correct
9 Partially correct 1 ms 208 KB Partially correct
10 Partially correct 0 ms 208 KB Partially correct
11 Partially correct 1 ms 208 KB Partially correct
12 Partially correct 1 ms 208 KB Partially correct
13 Partially correct 0 ms 208 KB Partially correct
14 Partially correct 1 ms 208 KB Partially correct
15 Partially correct 1 ms 208 KB Partially correct
16 Partially correct 1 ms 208 KB Partially correct
17 Partially correct 1 ms 208 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 204 KB Partially correct
2 Partially correct 1 ms 336 KB Partially correct
3 Partially correct 1 ms 336 KB Partially correct
4 Partially correct 1 ms 336 KB Partially correct
5 Partially correct 1 ms 336 KB Partially correct
6 Partially correct 1 ms 336 KB Partially correct
7 Partially correct 1 ms 464 KB Partially correct
8 Partially correct 1 ms 336 KB Partially correct
9 Partially correct 1 ms 336 KB Partially correct
10 Partially correct 1 ms 336 KB Partially correct
11 Partially correct 1 ms 336 KB Partially correct
12 Partially correct 1 ms 336 KB Partially correct
13 Partially correct 1 ms 320 KB Partially correct
14 Partially correct 1 ms 336 KB Partially correct
15 Partially correct 1 ms 336 KB Partially correct
16 Partially correct 1 ms 336 KB Partially correct
17 Partially correct 1 ms 336 KB Partially correct
18 Partially correct 1 ms 384 KB Partially correct
19 Partially correct 1 ms 336 KB Partially correct
20 Partially correct 1 ms 372 KB Partially correct
21 Partially correct 1 ms 336 KB Partially correct
22 Partially correct 1 ms 336 KB Partially correct
23 Partially correct 1 ms 316 KB Partially correct
24 Partially correct 1 ms 316 KB Partially correct
25 Partially correct 1 ms 336 KB Partially correct
26 Partially correct 1 ms 336 KB Partially correct
27 Partially correct 1 ms 336 KB Partially correct
28 Partially correct 1 ms 348 KB Partially correct
29 Partially correct 2 ms 372 KB Partially correct
30 Partially correct 1 ms 336 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 204 KB Partially correct
2 Partially correct 1 ms 208 KB Partially correct
3 Partially correct 0 ms 208 KB Partially correct
4 Partially correct 0 ms 208 KB Partially correct
5 Partially correct 1 ms 208 KB Partially correct
6 Partially correct 1 ms 208 KB Partially correct
7 Partially correct 0 ms 208 KB Partially correct
8 Partially correct 1 ms 316 KB Partially correct
9 Partially correct 1 ms 208 KB Partially correct
10 Partially correct 0 ms 208 KB Partially correct
11 Partially correct 1 ms 208 KB Partially correct
12 Partially correct 1 ms 208 KB Partially correct
13 Partially correct 0 ms 208 KB Partially correct
14 Partially correct 1 ms 208 KB Partially correct
15 Partially correct 1 ms 208 KB Partially correct
16 Partially correct 1 ms 208 KB Partially correct
17 Partially correct 1 ms 208 KB Partially correct
18 Partially correct 1 ms 204 KB Partially correct
19 Partially correct 1 ms 336 KB Partially correct
20 Partially correct 1 ms 336 KB Partially correct
21 Partially correct 1 ms 336 KB Partially correct
22 Partially correct 1 ms 336 KB Partially correct
23 Partially correct 1 ms 336 KB Partially correct
24 Partially correct 1 ms 464 KB Partially correct
25 Partially correct 1 ms 336 KB Partially correct
26 Partially correct 1 ms 336 KB Partially correct
27 Partially correct 1 ms 336 KB Partially correct
28 Partially correct 1 ms 336 KB Partially correct
29 Partially correct 1 ms 336 KB Partially correct
30 Partially correct 1 ms 320 KB Partially correct
31 Partially correct 1 ms 336 KB Partially correct
32 Partially correct 1 ms 336 KB Partially correct
33 Partially correct 1 ms 336 KB Partially correct
34 Partially correct 1 ms 336 KB Partially correct
35 Partially correct 1 ms 384 KB Partially correct
36 Partially correct 1 ms 336 KB Partially correct
37 Partially correct 1 ms 372 KB Partially correct
38 Partially correct 1 ms 336 KB Partially correct
39 Partially correct 1 ms 336 KB Partially correct
40 Partially correct 1 ms 316 KB Partially correct
41 Partially correct 1 ms 316 KB Partially correct
42 Partially correct 1 ms 336 KB Partially correct
43 Partially correct 1 ms 336 KB Partially correct
44 Partially correct 1 ms 336 KB Partially correct
45 Partially correct 1 ms 348 KB Partially correct
46 Partially correct 2 ms 372 KB Partially correct
47 Partially correct 1 ms 336 KB Partially correct
48 Partially correct 60 ms 7820 KB Partially correct
49 Partially correct 92 ms 8672 KB Partially correct
50 Partially correct 70 ms 8648 KB Partially correct
51 Partially correct 52 ms 6728 KB Partially correct
52 Partially correct 80 ms 8496 KB Partially correct
53 Partially correct 61 ms 7740 KB Partially correct
54 Partially correct 37 ms 9320 KB Partially correct
55 Partially correct 89 ms 19164 KB Partially correct
56 Partially correct 79 ms 13696 KB Partially correct
57 Partially correct 78 ms 12032 KB Partially correct
58 Partially correct 81 ms 10440 KB Partially correct
59 Partially correct 69 ms 8672 KB Partially correct
60 Partially correct 48 ms 8892 KB Partially correct
61 Partially correct 57 ms 9044 KB Partially correct
62 Partially correct 65 ms 8964 KB Partially correct
63 Partially correct 94 ms 8452 KB Partially correct
64 Partially correct 61 ms 8904 KB Partially correct
65 Partially correct 75 ms 9068 KB Partially correct
66 Partially correct 50 ms 8504 KB Partially correct
67 Partially correct 39 ms 6832 KB Partially correct
68 Partially correct 50 ms 7616 KB Partially correct
69 Partially correct 58 ms 9092 KB Partially correct
70 Partially correct 54 ms 8520 KB Partially correct
71 Partially correct 42 ms 6344 KB Partially correct
72 Partially correct 44 ms 7240 KB Partially correct
73 Partially correct 61 ms 9140 KB Partially correct
74 Partially correct 52 ms 8356 KB Partially correct
75 Partially correct 76 ms 8520 KB Partially correct
76 Partially correct 72 ms 8548 KB Partially correct
77 Partially correct 63 ms 8524 KB Partially correct
78 Partially correct 40 ms 5960 KB Partially correct
79 Partially correct 47 ms 6856 KB Partially correct
80 Partially correct 70 ms 8504 KB Partially correct
81 Partially correct 66 ms 8644 KB Partially correct
82 Partially correct 74 ms 8852 KB Partially correct