Submission #467571

# Submission time Handle Problem Language Result Execution time Memory
467571 2021-08-23T17:39:24 Z idk321 Mousetrap (CEOI17_mousetrap) C++17
0 / 100
346 ms 72324 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N = 1000005;
vector<int> adj[N];
int cost[N];

void dfs(int node, int par, int height) {
    if (par != -1 && adj[node].size() == 1) {
        cost[node] = height;
    }
    if (par != -1 && adj[node].size() == 2) {
        cost[node] = height + 1;
    }

    array<int, 2> most={0, 0};
    for (int next : adj[node]) {
        if (next == par) continue;
        dfs(next, node, height + 1);
        if (cost[next] > most[1]) most[1] = cost[next];
        if (most[1] > most[0]) swap(most[1], most[0]);
    }

    if (par != -1) {
        cost[node] = adj[node].size() - 2 + most[1];
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, t, m;
    cin >> n >> t >> m;
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    dfs(t, -1, 0);
    cout << cost[m] << "\n";
}
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 23732 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 346 ms 72324 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 23732 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 23732 KB Output isn't correct
2 Halted 0 ms 0 KB -