Submission #872623

# Submission time Handle Problem Language Result Execution time Memory
872623 2023-11-13T13:06:52 Z vjudge1 Mousetrap (CEOI17_mousetrap) C++17
0 / 100
244 ms 55084 KB
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

#define ONLINE_JUDGE
void solve() {
    int n, t, m;
    cin >> n >> t >> m;

    if(m == t) {
        cout << 0 << "\n";
        return;
    }

    vector <int> adj[n +1];
    for(int i = 1; i <= n -1; i++) {
        int u, v;
        cin >> u >> v;

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

    function <int(int, int)> dfs = [&](int node, int par) -> int {
        //cerr << node << " " << par << "\n";
        vector <int> chills;
        for(int child : adj[node]) {
            if(child == par) {
                continue;
            }

            chills.emplace_back(dfs(child, node) +2);
        }

        sort(chills.begin(), chills.end(), greater <> ());

        if(int(chills.size()) <= 1) {
            return 0;
        }
        
        //cerr << node << " " << par << " :: " << chills[1] << " " << int(chills.size()) << "\n";
        return chills[1] + int(chills.size()) -1;
    };

    cout << dfs(m, t) +1;
    
    return;
}

signed main() {
    #ifndef ONLINE_JUDGE
        freopen(".in", "r", stdin);
        freopen(".out", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int t = 1; //cin >> t;
    for(int i = 1; i <= t; i++) {
        solve();
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 244 ms 55084 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -