Submission #896147

# Submission time Handle Problem Language Result Execution time Memory
896147 2023-12-31T22:21:15 Z ShaShi Village (BOI20_village) C++17
0 / 100
5 ms 5468 KB
#include <bits/stdc++.h>
// #define int long long 
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define kill(x) cout << x << endl, exit(0);
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
 
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
 
const int MAXN = (int)1e5 + 7;
const int MOD = 998244353;
const int INF = (int)1e9 + 7;
 
 
 
int n, m, t, flag, k, u, v, w, ans, ans2, tmp, tmp2, tmp3, tmp4;
int arr[MAXN], arr2[MAXN], par[MAXN], h[MAXN];
vector<int> adj[MAXN];

int DFS(int v, int p=-1) {
    int res = 0;

    for (int u:adj[v]) {
        if (u == p) continue;

        res += DFS(u, v);
    }

    if (res) return 0;

    if (v != 1) {
        swap(arr[v], arr[p]);
        ans++;
        return 1;
    }

    swap(arr[1], arr[adj[1][0]]);
    ans++;
}


int32_t main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
    cin >> n;

    for (int i=1; i<n; i++) {
        cin >> u >> v;

        adj[u].pb(v);
        adj[v].pb(u);
    }

    // Min 
    for (int i=1; i<=n; i++) arr[i] = i;
    DFS(1);
    for (int i=1; i<=n; i++) arr2[arr[i]] = i;

    cout << 2*ans << " " << 0 << endl;

    for (int i=1; i<=n; i++) cout << arr2[i] << " ";
    cout << endl;



    for (int i=1; i<=n; i++) cout << arr2[i] << " ";
    cout << endl;


 
    return 0;
}

Compilation message

Village.cpp: In function 'int DFS(int, int)':
Village.cpp:45:8: warning: control reaches end of non-void function [-Wreturn-type]
   45 |     ans++;
      |     ~~~^~
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 2652 KB Partially correct
2 Runtime error 5 ms 5468 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 5468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 2652 KB Partially correct
2 Runtime error 5 ms 5468 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -