답안 #571471

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
571471 2022-06-02T09:43:29 Z piOOE Mousetrap (CEOI17_mousetrap) C++17
25 / 100
679 ms 73376 KB
#include <bits/stdc++.h>

using namespace std;

#define sz(x) ((int)size(x))
#define all(x) begin(x), end(x)
#define trace(x) cout << #x << ": " << (x) << endl;

typedef long long ll;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int rand(int l, int r) { return (int) ((ll) rnd() % (r - l + 1)) + l; }

template<typename T>
bool ckmn(T &x, T y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}

template<typename T>
bool ckmx(T &x, T y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}

const int N = 1000001, infI = 1e9 + 7;
const ll infL = 3e18;

int n, t, m;
vector<int> g[N];
int dp[N];

void dfs(int v, int p) {
    int mx1 = 0, mx2 = 0, cnt = 0;
    for (int to : g[v]) {
        if (to != p) {
            ++cnt;
            dfs(to, v);
            if (mx1 < dp[to]) {
                mx2 = mx1;
                mx1 = dp[to];
            } else if (mx2 < dp[to]){
                mx2 = dp[to];
            }
        }
    }
    dp[v] = 1 + mx2 + (cnt - 1);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> t >> m;
    --t, --m;
    for (int i = 1; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(t, -1);
    cout << dp[m];
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 23764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 290 ms 72344 KB Output is correct
2 Correct 252 ms 67384 KB Output is correct
3 Correct 659 ms 73376 KB Output is correct
4 Correct 290 ms 48380 KB Output is correct
5 Correct 679 ms 73300 KB Output is correct
6 Correct 663 ms 73292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 23764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 23764 KB Output isn't correct
2 Halted 0 ms 0 KB -