답안 #157215

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
157215 2019-10-10T06:47:34 Z lyc Mousetrap (CEOI17_mousetrap) C++14
40 / 100
973 ms 91596 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]-1-d[u] << endl;
                if (w[v]-(u!=M)-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 47480 KB Output is correct
2 Correct 46 ms 47352 KB Output is correct
3 Correct 46 ms 47352 KB Output is correct
4 Correct 46 ms 47352 KB Output is correct
5 Correct 45 ms 47224 KB Output is correct
6 Correct 46 ms 47352 KB Output is correct
7 Correct 45 ms 47356 KB Output is correct
8 Correct 46 ms 47352 KB Output is correct
9 Correct 46 ms 47352 KB Output is correct
10 Correct 46 ms 47352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 449 ms 90372 KB Output is correct
2 Correct 419 ms 86136 KB Output is correct
3 Incorrect 973 ms 91596 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 47480 KB Output is correct
2 Correct 46 ms 47352 KB Output is correct
3 Correct 46 ms 47352 KB Output is correct
4 Correct 46 ms 47352 KB Output is correct
5 Correct 45 ms 47224 KB Output is correct
6 Correct 46 ms 47352 KB Output is correct
7 Correct 45 ms 47356 KB Output is correct
8 Correct 46 ms 47352 KB Output is correct
9 Correct 46 ms 47352 KB Output is correct
10 Correct 46 ms 47352 KB Output is correct
11 Correct 46 ms 47252 KB Output is correct
12 Correct 46 ms 47352 KB Output is correct
13 Correct 46 ms 47352 KB Output is correct
14 Correct 46 ms 47480 KB Output is correct
15 Correct 47 ms 47352 KB Output is correct
16 Correct 47 ms 47356 KB Output is correct
17 Correct 46 ms 47352 KB Output is correct
18 Correct 47 ms 47364 KB Output is correct
19 Correct 46 ms 47352 KB Output is correct
20 Correct 46 ms 47352 KB Output is correct
21 Correct 47 ms 47352 KB Output is correct
22 Correct 54 ms 47352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 47480 KB Output is correct
2 Correct 46 ms 47352 KB Output is correct
3 Correct 46 ms 47352 KB Output is correct
4 Correct 46 ms 47352 KB Output is correct
5 Correct 45 ms 47224 KB Output is correct
6 Correct 46 ms 47352 KB Output is correct
7 Correct 45 ms 47356 KB Output is correct
8 Correct 46 ms 47352 KB Output is correct
9 Correct 46 ms 47352 KB Output is correct
10 Correct 46 ms 47352 KB Output is correct
11 Correct 449 ms 90372 KB Output is correct
12 Correct 419 ms 86136 KB Output is correct
13 Incorrect 973 ms 91596 KB Output isn't correct
14 Halted 0 ms 0 KB -