답안 #157214

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
157214 2019-10-10T06:39:40 Z lyc Mousetrap (CEOI17_mousetrap) C++14
0 / 100
942 ms 104768 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

const int MX_N = 1e6+5;

int N, T, M, A, B;
vector<int> al[MX_N];
int w[MX_N], d[MX_N], pa[MX_N];
vector<ii> sub[MX_N];

void dfs(int u, int p) {
    for (auto v : al[u]) if (v != p) {
        pa[v] = u;
        d[v] = d[u] + 1;
        w[v] = w[u] + SZ(al[u])-1-(p!=0);
        dfs(v,u);
    }
    if (SZ(al[u]) != 1) {
        int a = 0, b = 0;
        for (auto v : al[u]) if (v != p) {
            if (w[v] > a) a = w[v];
            else if (w[v] > b) b = w[v];
        }
        if (b) w[u] = b;
        else w[u] += d[u]+1;
    } else w[u] += d[u];
    //cout << u << " :: " << w[u] << " " << d[u] << "\n";
}

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> N >> T >> M;
    FOR(i,1,N-1){
        cin >> A >> B;
        al[A].push_back(B);
        al[B].push_back(A);
    }

    dfs(T,0);
    int lo = -1, hi = 2*N;
    while (hi-lo > 1) {
        int mid = (lo+hi)/2;

        int p, u, i, b, bad = 0;
        for (p = -1, u = M, i = 0, b = 0; pa[u] != 0; p = u, u = pa[u], ++i) {
            //cout << "\tTRAVERSE " << u << endl;
            int x = 0;
            for (int v : al[u]) if (v != pa[u] && v != p) {
                //cout << "\t\tNEI " << v << " :: " << w[v]-d[u] << endl;
                if (w[v]-d[u]+b > mid) ++x;
            }
            b += x;
            if (b > i+1) bad = 1;
        }
        if (b > mid) bad = 1;

        //cout << mid << " :: " << bad << endl;
        (bad ? lo : hi) = mid;
    }

    cout << hi << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 47352 KB Output is correct
2 Correct 46 ms 47352 KB Output is correct
3 Correct 45 ms 47352 KB Output is correct
4 Correct 46 ms 47368 KB Output is correct
5 Correct 46 ms 47352 KB Output is correct
6 Correct 46 ms 47352 KB Output is correct
7 Correct 46 ms 47352 KB Output is correct
8 Incorrect 46 ms 47352 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 487 ms 90356 KB Output is correct
2 Correct 418 ms 98104 KB Output is correct
3 Incorrect 942 ms 104768 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 47352 KB Output is correct
2 Correct 46 ms 47352 KB Output is correct
3 Correct 45 ms 47352 KB Output is correct
4 Correct 46 ms 47368 KB Output is correct
5 Correct 46 ms 47352 KB Output is correct
6 Correct 46 ms 47352 KB Output is correct
7 Correct 46 ms 47352 KB Output is correct
8 Incorrect 46 ms 47352 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 47352 KB Output is correct
2 Correct 46 ms 47352 KB Output is correct
3 Correct 45 ms 47352 KB Output is correct
4 Correct 46 ms 47368 KB Output is correct
5 Correct 46 ms 47352 KB Output is correct
6 Correct 46 ms 47352 KB Output is correct
7 Correct 46 ms 47352 KB Output is correct
8 Incorrect 46 ms 47352 KB Output isn't correct
9 Halted 0 ms 0 KB -