답안 #161198

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
161198 2019-11-01T11:47:15 Z Minnakhmetov Mousetrap (CEOI17_mousetrap) C++14
25 / 100
1173 ms 56452 KB
#include <bits/stdc++.h>
    
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
 
using namespace std;

const int N = 1e6 + 5;
vector<int> g[N];
int n, m, t;
bool term[N];

void dive(int node, int anc) {
    if (node == t)
        term[node] = 1;
    for (int to : g[node]) {
        if (to != anc) {
            dive(to, node);
            if (term[to])
                term[node] = 1;
        }
    }
}

int dfs(int node, int anc) {
    if (node == t)
        return 0;
    int adj = g[node].size() - (anc != -1);

    vector<int> v;

    for (int to : g[node]) {
        if (to != anc) {
            v.push_back(dfs(to, node) + !term[to]);
        }
    }

    sort(v.rbegin(), v.rend());

    if (v.empty())
        return 0;
    else if (v.size() == 1)
        return 1;

    return v[1] + adj - 1 - term[node];
}
 
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);

    cin >> n >> t >> m;

    m--, t--;

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

    // g[m].erase(find(all(g[m]), t));

    dive(m, -1);
    cout << dfs(m, -1);
 
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 23 ms 23800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 490 ms 55148 KB Output is correct
2 Correct 464 ms 52036 KB Output is correct
3 Correct 1173 ms 56452 KB Output is correct
4 Correct 551 ms 40184 KB Output is correct
5 Correct 1161 ms 56312 KB Output is correct
6 Correct 1167 ms 56304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 23 ms 23800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 23 ms 23800 KB Output isn't correct
2 Halted 0 ms 0 KB -