Submission #932304

# Submission time Handle Problem Language Result Execution time Memory
932304 2024-02-23T07:48:12 Z amirhoseinfar1385 Village (BOI20_village) C++17
Compilation error
0 ms 0 KB
// In the name of the God
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define pii pair <int, int>
#define smin(x, y) (x) = min((x), (y))
#define smax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(), (x).end()
using namespace std;

const int inf = 1e9+7;
const int mod = 998244353;
const int maxn = 1e5+5;

int n, res1 = 0, res2 = 0, f1[maxn], f2[maxn], sz[maxn], match[maxn];
vector <int> adj[maxn], vec;

void dfs1(int v, int p) {
    for (int u : adj[v]) {
        if (u != p) dfs1(u, v);
    }
    if (match[v] == v) {
        if (v == 1) {
            int u = adj[1][0];
            swap(match[1], match[u]);
        }
        else swap(match[v], match[p]);
        res1 += 2;
    }
}

void dfs2(int v, int p) {
    sz[v] = 1;
    for (int u : adj[v]) {
        if (u != p) {
            dfs2(u, v); sz[v] += sz[u];
        }
    }
}

int dfs3(int v, int p) {
    for(int u : adj[v]) {
        if (u != p and sz[u]*2 > sz[1]) return dfs3(u, v);
    }
    return v;
}

void dfs4(int v, int p, int h = 0) {
    vec.pb(v);
    res2 += h*2;
    for(int u : adj[v]) {
        if (u != p) dfs4(u, v, h+1);
    }
}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i < n; i++) {
        int v, u; cin >> v >> u;
        adj[v].pb(u);
        adj[u].pb(v);
    }
    for (int i = 1; i <= n; i++) match[i] = i;
    dfs1(1, 1);
    for (int i = 1; i <= n; i++) f1[match[i]] = i;
    dfs2(1, 1);
    int c = dfs3(1, 1);
    dfs4(c, c);
    for (int i = 0; i < n; i++) f2[vec[i]] = vec[(i+n/2)%n];
    cout << res1 << ' ' << res2 << '\n';
    for (int i = 1; i <= n; i++) cout << f1[i] << ' ';
    cout << '\n';
    for (int i = 1; i <= n; i++) cout << f2[i] << ' ';
    cout << '\n';
    return 0;
}




















 

Compilation message

Village.cpp:102:1: error: extended character   is not valid in an identifier
  102 |  
      | ^
Village.cpp:102:1: error: '\U000000a0' does not name a type
  102 |  
      | ^