답안 #342269

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
342269 2021-01-01T17:17:33 Z richyrich 경주 (Race) (IOI11_race) C++17
43 / 100
2276 ms 128236 KB
//#include "race.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll NMAX = 2e5+20;
const ll inf = 1e18;
ll n, eul[NMAX], siz[NMAX], in[NMAX], out[NMAX], edges[NMAX], timer, d[NMAX],ans,k;
vector<vector<pair<ll,ll>>> g(NMAX);
void dfs1(ll x, ll par) {
    siz[x] = 1;
    in[x] = timer;
    eul[timer++] = x;
    for(auto c : g[x]) {
        ll y = c.first;
        if(y==par) continue;
        edges[y] = edges[x] + 1;
        d[y] = d[x] + c.second;
        dfs1(y, x);
        siz[x] += siz[y];
    }
    out[x] = timer;
}
map<ll, map<ll,ll>> M;
void add(ll x, ll ancst) {
    M[d[x]][edges[x]]++;
}
void remove(ll x) {
    M[d[x]][edges[x]]--;
    if(M[d[x]][edges[x]] == 0) M[d[x]].erase(edges[x]);
    if(M[d[x]].empty())M.erase(d[x]);
    //printf("removing %d\n", x);
}
//ll check[NMAX];
void dfs2(ll x, ll p, bool keep, ll level) {
    ll mx = -1, bigc = -1;
    for(auto c : g[x]) {
        ll y = c.first;
        if(y == p) continue;
        if(siz[y] > mx) {
            mx = siz[y], bigc = y;
        }
    }
    for(auto c : g[x]) {
        ll y = c.first;    
        if(y != p && y != bigc) {
            dfs2(y,x,0,level+1);

        }
    }
    if(bigc != -1) {
        dfs2( bigc, x, 1, level+1);
        if(!M[k + d[x]].empty()) {
            ans = min(ans, (M[k + d[x]].begin())->first - edges[x]);
        }
    }
    for(auto c : g[x]) {
        ll y = c.first;
        if(y != p && y != bigc) {
            for(ll i = in[y]; i < out[y]; i++) {
                if(k + 2 * d[x] - d[eul[i]] == 0) {
                    ans = min(ans, edges[eul[i]] - edges[x]);
                }
                else if(!M[k + 2 * d[x] - d[eul[i]]].empty()) {
                    ll a = edges[eul[i]], b = (M[k + 2 * d[x] - d[eul[i]]].begin())->first;
                    ans = min(ans, a + b - 2 * edges[x]);
                }
                add(eul[i], x);
            }
        }
    }
    add(x, p);  
    if(!keep) {
        for(ll i = in[x]; i < out[x]; i++) {
            remove(eul[i]);
        }
    }
}

int best_path(int N, int K, int H[][2], int L[]) {
    n = N;
    ans = inf;
    k = K;
    for(ll i = 0; i < n-1; i++) {
        ll x = H[i][0], y = H[i][1];
        g[x].push_back({y, L[i]}), g[y].push_back({x, L[i]});
    }
    timer = 1;
    edges[0] = 0;
    dfs1(0, -1);
    dfs2(0, -1, 0, 0);
    if(ans == inf) ans = -1;
    return ans;
}
/*
int main() {
    ll N, K;
    cin >> N >> K;
    ll H[N][2], L[N];
    n = N;
    for(ll i = 0; i < N-1; i++) {
        cin >> H[i][0] >> H[i][1] >> L[i];
    }
    for(ll i = 0; i < N-1; i++) {
        ll x = H[i][0], y = H[i][1];
        g[x].push_back({y, L[i]}), g[y].push_back({x, L[i]});
    }
    timer = 1;
    edges[0] = 0;
    k = K;
    dfs1(0, -1);
    ans = inf;
    dfs2(0, -1, 0, 0);
    printf("%lld\n", ans);
}
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 4 ms 5100 KB Output is correct
3 Correct 4 ms 5120 KB Output is correct
4 Correct 4 ms 5100 KB Output is correct
5 Correct 4 ms 5100 KB Output is correct
6 Correct 4 ms 5100 KB Output is correct
7 Correct 4 ms 5100 KB Output is correct
8 Correct 4 ms 5100 KB Output is correct
9 Correct 4 ms 5100 KB Output is correct
10 Correct 4 ms 5100 KB Output is correct
11 Correct 4 ms 5100 KB Output is correct
12 Correct 4 ms 5100 KB Output is correct
13 Correct 4 ms 5100 KB Output is correct
14 Correct 4 ms 5120 KB Output is correct
15 Correct 4 ms 5112 KB Output is correct
16 Correct 4 ms 5120 KB Output is correct
17 Correct 4 ms 5100 KB Output is correct
18 Correct 4 ms 5100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 4 ms 5100 KB Output is correct
3 Correct 4 ms 5120 KB Output is correct
4 Correct 4 ms 5100 KB Output is correct
5 Correct 4 ms 5100 KB Output is correct
6 Correct 4 ms 5100 KB Output is correct
7 Correct 4 ms 5100 KB Output is correct
8 Correct 4 ms 5100 KB Output is correct
9 Correct 4 ms 5100 KB Output is correct
10 Correct 4 ms 5100 KB Output is correct
11 Correct 4 ms 5100 KB Output is correct
12 Correct 4 ms 5100 KB Output is correct
13 Correct 4 ms 5100 KB Output is correct
14 Correct 4 ms 5120 KB Output is correct
15 Correct 4 ms 5112 KB Output is correct
16 Correct 4 ms 5120 KB Output is correct
17 Correct 4 ms 5100 KB Output is correct
18 Correct 4 ms 5100 KB Output is correct
19 Correct 4 ms 5100 KB Output is correct
20 Correct 4 ms 5100 KB Output is correct
21 Correct 6 ms 5356 KB Output is correct
22 Correct 7 ms 5612 KB Output is correct
23 Correct 7 ms 5612 KB Output is correct
24 Correct 7 ms 5612 KB Output is correct
25 Correct 6 ms 5612 KB Output is correct
26 Correct 7 ms 5612 KB Output is correct
27 Correct 5 ms 5228 KB Output is correct
28 Correct 7 ms 5612 KB Output is correct
29 Correct 7 ms 5612 KB Output is correct
30 Correct 8 ms 5612 KB Output is correct
31 Correct 7 ms 5612 KB Output is correct
32 Correct 8 ms 5612 KB Output is correct
33 Correct 7 ms 5612 KB Output is correct
34 Correct 6 ms 5484 KB Output is correct
35 Correct 5 ms 5484 KB Output is correct
36 Correct 5 ms 5484 KB Output is correct
37 Correct 5 ms 5484 KB Output is correct
38 Correct 6 ms 5484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 4 ms 5100 KB Output is correct
3 Correct 4 ms 5120 KB Output is correct
4 Correct 4 ms 5100 KB Output is correct
5 Correct 4 ms 5100 KB Output is correct
6 Correct 4 ms 5100 KB Output is correct
7 Correct 4 ms 5100 KB Output is correct
8 Correct 4 ms 5100 KB Output is correct
9 Correct 4 ms 5100 KB Output is correct
10 Correct 4 ms 5100 KB Output is correct
11 Correct 4 ms 5100 KB Output is correct
12 Correct 4 ms 5100 KB Output is correct
13 Correct 4 ms 5100 KB Output is correct
14 Correct 4 ms 5120 KB Output is correct
15 Correct 4 ms 5112 KB Output is correct
16 Correct 4 ms 5120 KB Output is correct
17 Correct 4 ms 5100 KB Output is correct
18 Correct 4 ms 5100 KB Output is correct
19 Correct 329 ms 16364 KB Output is correct
20 Correct 331 ms 17772 KB Output is correct
21 Correct 317 ms 17644 KB Output is correct
22 Correct 307 ms 17760 KB Output is correct
23 Correct 553 ms 18668 KB Output is correct
24 Correct 361 ms 17348 KB Output is correct
25 Correct 150 ms 32492 KB Output is correct
26 Correct 99 ms 38912 KB Output is correct
27 Correct 390 ms 34412 KB Output is correct
28 Correct 464 ms 110572 KB Output is correct
29 Correct 483 ms 109420 KB Output is correct
30 Correct 421 ms 34540 KB Output is correct
31 Correct 398 ms 34284 KB Output is correct
32 Correct 550 ms 34924 KB Output is correct
33 Correct 477 ms 30004 KB Output is correct
34 Correct 2276 ms 128236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 4 ms 5100 KB Output is correct
3 Correct 4 ms 5120 KB Output is correct
4 Correct 4 ms 5100 KB Output is correct
5 Correct 4 ms 5100 KB Output is correct
6 Correct 4 ms 5100 KB Output is correct
7 Correct 4 ms 5100 KB Output is correct
8 Correct 4 ms 5100 KB Output is correct
9 Correct 4 ms 5100 KB Output is correct
10 Correct 4 ms 5100 KB Output is correct
11 Correct 4 ms 5100 KB Output is correct
12 Correct 4 ms 5100 KB Output is correct
13 Correct 4 ms 5100 KB Output is correct
14 Correct 4 ms 5120 KB Output is correct
15 Correct 4 ms 5112 KB Output is correct
16 Correct 4 ms 5120 KB Output is correct
17 Correct 4 ms 5100 KB Output is correct
18 Correct 4 ms 5100 KB Output is correct
19 Correct 4 ms 5100 KB Output is correct
20 Correct 4 ms 5100 KB Output is correct
21 Correct 6 ms 5356 KB Output is correct
22 Correct 7 ms 5612 KB Output is correct
23 Correct 7 ms 5612 KB Output is correct
24 Correct 7 ms 5612 KB Output is correct
25 Correct 6 ms 5612 KB Output is correct
26 Correct 7 ms 5612 KB Output is correct
27 Correct 5 ms 5228 KB Output is correct
28 Correct 7 ms 5612 KB Output is correct
29 Correct 7 ms 5612 KB Output is correct
30 Correct 8 ms 5612 KB Output is correct
31 Correct 7 ms 5612 KB Output is correct
32 Correct 8 ms 5612 KB Output is correct
33 Correct 7 ms 5612 KB Output is correct
34 Correct 6 ms 5484 KB Output is correct
35 Correct 5 ms 5484 KB Output is correct
36 Correct 5 ms 5484 KB Output is correct
37 Correct 5 ms 5484 KB Output is correct
38 Correct 6 ms 5484 KB Output is correct
39 Correct 329 ms 16364 KB Output is correct
40 Correct 331 ms 17772 KB Output is correct
41 Correct 317 ms 17644 KB Output is correct
42 Correct 307 ms 17760 KB Output is correct
43 Correct 553 ms 18668 KB Output is correct
44 Correct 361 ms 17348 KB Output is correct
45 Correct 150 ms 32492 KB Output is correct
46 Correct 99 ms 38912 KB Output is correct
47 Correct 390 ms 34412 KB Output is correct
48 Correct 464 ms 110572 KB Output is correct
49 Correct 483 ms 109420 KB Output is correct
50 Correct 421 ms 34540 KB Output is correct
51 Correct 398 ms 34284 KB Output is correct
52 Correct 550 ms 34924 KB Output is correct
53 Correct 477 ms 30004 KB Output is correct
54 Correct 2276 ms 128236 KB Output is correct
55 Correct 46 ms 8044 KB Output is correct
56 Correct 21 ms 6372 KB Output is correct
57 Incorrect 211 ms 17772 KB Output isn't correct
58 Halted 0 ms 0 KB -