답안 #857956

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
857956 2023-10-07T07:58:30 Z Trisanu_Das Village (BOI20_village) C++17
50 / 100
76 ms 18256 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
 
ll n, ans[100005], resx;
vector<ll> adj[100005];
 
pair<ll, ll> S(ll x, ll y){
    vector<pair<ll, ll> > a;
    a.clear();
    pair<ll, ll> b;
    for(int i = 0; i < adj[x].size(); i++){
        if(adj[x][i] != y){
            b = S(adj[x][i], x);
            if(b.first == b.second) a.push_back(b);
        }
    }
    if(a.size() == 0){
        if(y == 0){
            ans[b.second] = x;
            ans[x] = b.first;
            resx += 2;
            return {0, 0};
        }else return {x, x};
    }else{
        a.push_back({x, x});
        ll m = a.size() - 2;
        for(int i=0;i<=m;i++){
            ans[a[i].first] = a[i + 1].first;
            resx += 2;
        }
        ans[x] = a[0].first;
        return {x, a[m].first};
    }
}
 
int main(){
    cin >> n;
    for(int i=1;i<n;i++){
        ll u, v; cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    S(1, 0);
    cout << resx << ' ' << 0 << '\n';
    for(int i = 1; i <= n; i++) cout << ans[i] << ' ';
    cout << '\n';
    for(int i = 1; i <= n; i++) cout << i << ' ';
    cout << '\n';
}

Compilation message

Village.cpp: In function 'std::pair<long long int, long long int> S(long long int, long long int)':
Village.cpp:12:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for(int i = 0; i < adj[x].size(); i++){
      |                    ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 2648 KB Partially correct
2 Partially correct 1 ms 2648 KB Partially correct
3 Partially correct 1 ms 2652 KB Partially correct
4 Partially correct 1 ms 2652 KB Partially correct
5 Partially correct 1 ms 2652 KB Partially correct
6 Partially correct 1 ms 2652 KB Partially correct
7 Partially correct 1 ms 2652 KB Partially correct
8 Partially correct 1 ms 2652 KB Partially correct
9 Partially correct 1 ms 2648 KB Partially correct
10 Partially correct 1 ms 2648 KB Partially correct
11 Partially correct 1 ms 2652 KB Partially correct
12 Partially correct 1 ms 2652 KB Partially correct
13 Partially correct 1 ms 2652 KB Partially correct
14 Partially correct 1 ms 2652 KB Partially correct
15 Partially correct 1 ms 2648 KB Partially correct
16 Partially correct 1 ms 2648 KB Partially correct
17 Partially correct 1 ms 2648 KB Partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 2652 KB Partially correct
2 Partially correct 1 ms 2652 KB Partially correct
3 Partially correct 1 ms 2652 KB Partially correct
4 Partially correct 1 ms 2652 KB Partially correct
5 Partially correct 1 ms 2652 KB Partially correct
6 Partially correct 1 ms 2648 KB Partially correct
7 Partially correct 1 ms 2652 KB Partially correct
8 Partially correct 1 ms 2652 KB Partially correct
9 Partially correct 1 ms 2664 KB Partially correct
10 Partially correct 1 ms 2652 KB Partially correct
11 Partially correct 1 ms 2652 KB Partially correct
12 Partially correct 1 ms 2652 KB Partially correct
13 Partially correct 1 ms 2652 KB Partially correct
14 Partially correct 1 ms 2652 KB Partially correct
15 Partially correct 1 ms 2652 KB Partially correct
16 Partially correct 1 ms 2904 KB Partially correct
17 Partially correct 1 ms 2652 KB Partially correct
18 Partially correct 1 ms 2652 KB Partially correct
19 Partially correct 2 ms 2652 KB Partially correct
20 Partially correct 1 ms 2652 KB Partially correct
21 Partially correct 2 ms 2652 KB Partially correct
22 Partially correct 1 ms 2652 KB Partially correct
23 Partially correct 1 ms 2648 KB Partially correct
24 Partially correct 1 ms 2652 KB Partially correct
25 Partially correct 1 ms 2692 KB Partially correct
26 Partially correct 1 ms 2652 KB Partially correct
27 Partially correct 1 ms 2820 KB Partially correct
28 Partially correct 1 ms 2652 KB Partially correct
29 Partially correct 1 ms 2652 KB Partially correct
30 Partially correct 2 ms 2652 KB Partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 2648 KB Partially correct
2 Partially correct 1 ms 2648 KB Partially correct
3 Partially correct 1 ms 2652 KB Partially correct
4 Partially correct 1 ms 2652 KB Partially correct
5 Partially correct 1 ms 2652 KB Partially correct
6 Partially correct 1 ms 2652 KB Partially correct
7 Partially correct 1 ms 2652 KB Partially correct
8 Partially correct 1 ms 2652 KB Partially correct
9 Partially correct 1 ms 2648 KB Partially correct
10 Partially correct 1 ms 2648 KB Partially correct
11 Partially correct 1 ms 2652 KB Partially correct
12 Partially correct 1 ms 2652 KB Partially correct
13 Partially correct 1 ms 2652 KB Partially correct
14 Partially correct 1 ms 2652 KB Partially correct
15 Partially correct 1 ms 2648 KB Partially correct
16 Partially correct 1 ms 2648 KB Partially correct
17 Partially correct 1 ms 2648 KB Partially correct
18 Partially correct 1 ms 2652 KB Partially correct
19 Partially correct 1 ms 2652 KB Partially correct
20 Partially correct 1 ms 2652 KB Partially correct
21 Partially correct 1 ms 2652 KB Partially correct
22 Partially correct 1 ms 2652 KB Partially correct
23 Partially correct 1 ms 2648 KB Partially correct
24 Partially correct 1 ms 2652 KB Partially correct
25 Partially correct 1 ms 2652 KB Partially correct
26 Partially correct 1 ms 2664 KB Partially correct
27 Partially correct 1 ms 2652 KB Partially correct
28 Partially correct 1 ms 2652 KB Partially correct
29 Partially correct 1 ms 2652 KB Partially correct
30 Partially correct 1 ms 2652 KB Partially correct
31 Partially correct 1 ms 2652 KB Partially correct
32 Partially correct 1 ms 2652 KB Partially correct
33 Partially correct 1 ms 2904 KB Partially correct
34 Partially correct 1 ms 2652 KB Partially correct
35 Partially correct 1 ms 2652 KB Partially correct
36 Partially correct 2 ms 2652 KB Partially correct
37 Partially correct 1 ms 2652 KB Partially correct
38 Partially correct 2 ms 2652 KB Partially correct
39 Partially correct 1 ms 2652 KB Partially correct
40 Partially correct 1 ms 2648 KB Partially correct
41 Partially correct 1 ms 2652 KB Partially correct
42 Partially correct 1 ms 2692 KB Partially correct
43 Partially correct 1 ms 2652 KB Partially correct
44 Partially correct 1 ms 2820 KB Partially correct
45 Partially correct 1 ms 2652 KB Partially correct
46 Partially correct 1 ms 2652 KB Partially correct
47 Partially correct 2 ms 2652 KB Partially correct
48 Partially correct 62 ms 7764 KB Partially correct
49 Partially correct 66 ms 8320 KB Partially correct
50 Partially correct 66 ms 8528 KB Partially correct
51 Partially correct 52 ms 7020 KB Partially correct
52 Partially correct 71 ms 8272 KB Partially correct
53 Partially correct 58 ms 7760 KB Partially correct
54 Partially correct 36 ms 10144 KB Partially correct
55 Partially correct 76 ms 18256 KB Partially correct
56 Partially correct 72 ms 13396 KB Partially correct
57 Partially correct 76 ms 11744 KB Partially correct
58 Partially correct 72 ms 10152 KB Partially correct
59 Partially correct 68 ms 8528 KB Partially correct
60 Partially correct 69 ms 9028 KB Partially correct
61 Partially correct 60 ms 9964 KB Partially correct
62 Partially correct 61 ms 9880 KB Partially correct
63 Partially correct 60 ms 9556 KB Partially correct
64 Partially correct 63 ms 10068 KB Partially correct
65 Partially correct 58 ms 10068 KB Partially correct
66 Partially correct 58 ms 9628 KB Partially correct
67 Partially correct 45 ms 8684 KB Partially correct
68 Partially correct 60 ms 9188 KB Partially correct
69 Partially correct 72 ms 10196 KB Partially correct
70 Partially correct 67 ms 9612 KB Partially correct
71 Partially correct 44 ms 7820 KB Partially correct
72 Partially correct 47 ms 8528 KB Partially correct
73 Partially correct 63 ms 10148 KB Partially correct
74 Partially correct 63 ms 9596 KB Partially correct
75 Partially correct 66 ms 10068 KB Partially correct
76 Partially correct 64 ms 9296 KB Partially correct
77 Partially correct 61 ms 9768 KB Partially correct
78 Partially correct 43 ms 7296 KB Partially correct
79 Partially correct 49 ms 8048 KB Partially correct
80 Partially correct 67 ms 10068 KB Partially correct
81 Partially correct 60 ms 10068 KB Partially correct
82 Partially correct 58 ms 9656 KB Partially correct