Submission #1102019

# Submission time Handle Problem Language Result Execution time Memory
1102019 2024-10-17T10:16:03 Z crafticat Viruses (BOI20_viruses) C++17
0 / 100
226 ms 262144 KB
#include "bits/stdc++.h"

using namespace std;
template<typename T>
using V = vector<T>;
using vi = V<int>;
using vvi = V<vi>;
using pi = pair<int,int>;
using vpi = V<pi>;

#define F0R(i, n) for(int i = 0; i < n;i++)
#define FOR(i,a, n) for(int i = a; i < n;i++)
#define pb push_back

vvi g;
vi to;
vi dist;

void calc(int x, int p, int d = 0) {
    dist[x] = d;
    for (auto y : g[x]) {
        if (y == p) continue;
        calc(y,x, d + 1);
    }
}

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

    int n; cin >> n;
    g.resize(n + 1);
    to.resize(n + 1);
    dist.resize(n + 1);

    F0R(i, n - 1) {
        int a, b; cin >> a >> b;
        g[a].pb(b);
        g[b].pb(a);
    }

    int root = 1;
    int sum = 0;
    V<bool> vis(n + 1);

    while (true) {
        calc(root, -1, 0);
        int sel = -1;

        FOR(i,1,n + 1) {
            if (vis[i]) continue;
            if (sel == -1 || dist[i] > dist[sel]) sel = i;
        }

        if (sel == -1) break;
        to[root] = sel;
        vis[root] = true;
        root = sel;
        sum += dist[sel];
    }

    calc(root, -1, 0);
    to[root] = 1;
    sum += dist[1];

    cout << sum << " " << sum << "\n";
    FOR(i, 1, n + 1) {
        cout << to[i] << " ";
    }
    cout << "\n";
    FOR(i, 1, n + 1) {
        cout << to[i] << " ";
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 226 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -