답안 #434654

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
434654 2021-06-21T13:59:05 Z KoD Mousetrap (CEOI17_mousetrap) C++17
0 / 100
837 ms 72304 KB
#include <bits/stdc++.h>

template <class T> using Vec = std::vector<T>;

template <class F> struct RecLambda : private F {
    explicit RecLambda(F&& f) : F(std::forward<F>(f)) {}
    template <class... Args> decltype(auto) operator() (Args&&... args) const {
        return F::operator()(*this, std::forward<Args>(args)...);
    }
};

int main() {
    int N, T, M;
    std::cin >> N >> T >> M;
    T -= 1;
    M -= 1;
    Vec<Vec<int>> graph(N);
    for (int i = 0; i < N - 1; ++i) {
        int a, b;
        std::cin >> a >> b;
        a -= 1;
        b -= 1;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    Vec<int> parent(N, -1);
    RecLambda([&](auto&& dfs, const int u) -> void {
        for (const int v : graph[u]) {
            if (parent[u] != v) {
                parent[v] = u;
                dfs(v);
            }
        }
    })(T);
    int ans = RecLambda([&](auto&& dfs, const int u) -> int {
        int max = 0;
        for (const int v : graph[u]) {
            if (v != parent[u]) {
                max = std::max(max, dfs(v));
            }
        }
        return max + (int) graph[u].size() - 1;
    })(M);
    while (M != T) {
        ans += 1;
        M = parent[M];
    }
    std::cout << ans - 1 << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 837 ms 72304 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -