답안 #297163

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
297163 2020-09-11T10:11:11 Z Kastanda 경주 (Race) (IOI11_race) C++11
100 / 100
1018 ms 41488 KB
/*
    Take me to church
    I'll worship like a dog at the shrine of your lies
    I'll tell you my sins and you can sharpen your knife
    Offer me that deathless death
    Good God, let me give you my life
*/
#include<bits/stdc++.h>
#include "race.h"
#define x first
#define y second
using namespace std;
const int N = 200005, MXK = 2000006;
int n, k, Mn = N, M[N], SZ[N], qu[N], H[N], D[N], B[MXK];
vector < pair < int , int > > Adj[N];
vector < int > A;
void DFSSZ(int v, int p = -1)
{
    SZ[v] = 1;
    for (auto u : Adj[v])
        if (!M[u.x] && u.x != p)
            DFSSZ(u.x, v), SZ[v] += SZ[u.x];
}
inline int Centroid(int v)
{
    DFSSZ(v);
    int _n = SZ[v], w = 1, p = -1;
    while (w)
    {
        w = 0;
        for (auto u : Adj[v])
            if (!M[u.x] && u.x != p && SZ[u.x] * 2 > _n)
                {p = v; v = u.x; w = 1; break;}
    }
    return (v);
}
void DFS(int v, int p)
{
    A.push_back(v);
    if (D[v] <= k)
        Mn = min(Mn, H[v] + B[k - D[v]]);
    for (auto u : Adj[v])
        if (!M[u.x] && u.x != p)
            H[u.x] = H[v] + 1, D[u.x] = min(D[v] + u.y, MXK - 2), DFS(u.x, v);
}
void UNDFS(int v, int p)
{
    B[D[v]] = B[MXK - 1];
    for (auto u : Adj[v])
        if (!M[u.x] && u.x != p)
            UNDFS(u.x, v);
}
inline void Solve(int v)
{
    H[v] = D[v] = 0;
    for (auto u : Adj[v])
        if (!M[u.x])
        {
            H[u.x] = H[v] + 1;
            D[u.x] = D[v] + u.y;
            DFS(u.x, v);
            for (int w : A)
                B[D[w]] = min(B[D[w]], H[w]);
            A.clear();
        }
    for (auto u : Adj[v])
        if (!M[u.x])
            UNDFS(u.x, v);
}
inline void Decompose()
{
    int l = 0, r = 0;
    qu[r ++] = 0;
    while (r - l)
    {
        int v = Centroid(qu[l ++]);
        Solve(v); M[v] = 1;
        for (auto u : Adj[v])
            if (!M[u.x])
                qu[r ++] = u.x;
    }
}
int best_path(int _n, int _k, int _E[200000][2], int _L[200000])
{
    n = _n; k = _k;
    //cin >> n >> k;
    memset(B, 63, sizeof(B)); B[0] = 0;
    for (int i = 0; i < n - 1; i ++)
    {
        Adj[_E[i][0]].push_back({_E[i][1], _L[i]});
        Adj[_E[i][1]].push_back({_E[i][0], _L[i]});
        //int a, b, c;
        //cin >> a >> b >> c;
        //Adj[a].push_back({b, c});
        //Adj[b].push_back({a, c});
    }
    int l = 0, r = 0;
    Decompose();
    if (Mn == N)
        Mn = -1;
    //printf("%d\n", Mn);
    //return 0;
    return (Mn);
}

Compilation message

race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:97:9: warning: unused variable 'l' [-Wunused-variable]
   97 |     int l = 0, r = 0;
      |         ^
race.cpp:97:16: warning: unused variable 'r' [-Wunused-variable]
   97 |     int l = 0, r = 0;
      |                ^
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12928 KB Output is correct
2 Correct 8 ms 12928 KB Output is correct
3 Correct 9 ms 12928 KB Output is correct
4 Correct 8 ms 12928 KB Output is correct
5 Correct 8 ms 12928 KB Output is correct
6 Correct 8 ms 12928 KB Output is correct
7 Correct 9 ms 12960 KB Output is correct
8 Correct 10 ms 12928 KB Output is correct
9 Correct 9 ms 12928 KB Output is correct
10 Correct 8 ms 12928 KB Output is correct
11 Correct 9 ms 12928 KB Output is correct
12 Correct 10 ms 12928 KB Output is correct
13 Correct 9 ms 12928 KB Output is correct
14 Correct 9 ms 12928 KB Output is correct
15 Correct 9 ms 12904 KB Output is correct
16 Correct 9 ms 12928 KB Output is correct
17 Correct 9 ms 12928 KB Output is correct
18 Correct 9 ms 12928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12928 KB Output is correct
2 Correct 8 ms 12928 KB Output is correct
3 Correct 9 ms 12928 KB Output is correct
4 Correct 8 ms 12928 KB Output is correct
5 Correct 8 ms 12928 KB Output is correct
6 Correct 8 ms 12928 KB Output is correct
7 Correct 9 ms 12960 KB Output is correct
8 Correct 10 ms 12928 KB Output is correct
9 Correct 9 ms 12928 KB Output is correct
10 Correct 8 ms 12928 KB Output is correct
11 Correct 9 ms 12928 KB Output is correct
12 Correct 10 ms 12928 KB Output is correct
13 Correct 9 ms 12928 KB Output is correct
14 Correct 9 ms 12928 KB Output is correct
15 Correct 9 ms 12904 KB Output is correct
16 Correct 9 ms 12928 KB Output is correct
17 Correct 9 ms 12928 KB Output is correct
18 Correct 9 ms 12928 KB Output is correct
19 Correct 9 ms 12928 KB Output is correct
20 Correct 9 ms 12832 KB Output is correct
21 Correct 11 ms 12928 KB Output is correct
22 Correct 10 ms 12928 KB Output is correct
23 Correct 9 ms 12928 KB Output is correct
24 Correct 9 ms 12928 KB Output is correct
25 Correct 11 ms 12904 KB Output is correct
26 Correct 10 ms 12928 KB Output is correct
27 Correct 10 ms 12928 KB Output is correct
28 Correct 9 ms 13020 KB Output is correct
29 Correct 10 ms 12928 KB Output is correct
30 Correct 9 ms 12928 KB Output is correct
31 Correct 10 ms 12928 KB Output is correct
32 Correct 10 ms 12960 KB Output is correct
33 Correct 10 ms 12928 KB Output is correct
34 Correct 10 ms 13056 KB Output is correct
35 Correct 10 ms 12928 KB Output is correct
36 Correct 10 ms 12928 KB Output is correct
37 Correct 10 ms 12928 KB Output is correct
38 Correct 10 ms 12928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12928 KB Output is correct
2 Correct 8 ms 12928 KB Output is correct
3 Correct 9 ms 12928 KB Output is correct
4 Correct 8 ms 12928 KB Output is correct
5 Correct 8 ms 12928 KB Output is correct
6 Correct 8 ms 12928 KB Output is correct
7 Correct 9 ms 12960 KB Output is correct
8 Correct 10 ms 12928 KB Output is correct
9 Correct 9 ms 12928 KB Output is correct
10 Correct 8 ms 12928 KB Output is correct
11 Correct 9 ms 12928 KB Output is correct
12 Correct 10 ms 12928 KB Output is correct
13 Correct 9 ms 12928 KB Output is correct
14 Correct 9 ms 12928 KB Output is correct
15 Correct 9 ms 12904 KB Output is correct
16 Correct 9 ms 12928 KB Output is correct
17 Correct 9 ms 12928 KB Output is correct
18 Correct 9 ms 12928 KB Output is correct
19 Correct 346 ms 21344 KB Output is correct
20 Correct 340 ms 21368 KB Output is correct
21 Correct 321 ms 21368 KB Output is correct
22 Correct 289 ms 21364 KB Output is correct
23 Correct 245 ms 21676 KB Output is correct
24 Correct 121 ms 21496 KB Output is correct
25 Correct 271 ms 24056 KB Output is correct
26 Correct 139 ms 27112 KB Output is correct
27 Correct 371 ms 29560 KB Output is correct
28 Correct 1008 ms 41488 KB Output is correct
29 Correct 961 ms 40816 KB Output is correct
30 Correct 358 ms 29560 KB Output is correct
31 Correct 370 ms 29592 KB Output is correct
32 Correct 584 ms 29688 KB Output is correct
33 Correct 698 ms 28860 KB Output is correct
34 Correct 721 ms 29824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12928 KB Output is correct
2 Correct 8 ms 12928 KB Output is correct
3 Correct 9 ms 12928 KB Output is correct
4 Correct 8 ms 12928 KB Output is correct
5 Correct 8 ms 12928 KB Output is correct
6 Correct 8 ms 12928 KB Output is correct
7 Correct 9 ms 12960 KB Output is correct
8 Correct 10 ms 12928 KB Output is correct
9 Correct 9 ms 12928 KB Output is correct
10 Correct 8 ms 12928 KB Output is correct
11 Correct 9 ms 12928 KB Output is correct
12 Correct 10 ms 12928 KB Output is correct
13 Correct 9 ms 12928 KB Output is correct
14 Correct 9 ms 12928 KB Output is correct
15 Correct 9 ms 12904 KB Output is correct
16 Correct 9 ms 12928 KB Output is correct
17 Correct 9 ms 12928 KB Output is correct
18 Correct 9 ms 12928 KB Output is correct
19 Correct 9 ms 12928 KB Output is correct
20 Correct 9 ms 12832 KB Output is correct
21 Correct 11 ms 12928 KB Output is correct
22 Correct 10 ms 12928 KB Output is correct
23 Correct 9 ms 12928 KB Output is correct
24 Correct 9 ms 12928 KB Output is correct
25 Correct 11 ms 12904 KB Output is correct
26 Correct 10 ms 12928 KB Output is correct
27 Correct 10 ms 12928 KB Output is correct
28 Correct 9 ms 13020 KB Output is correct
29 Correct 10 ms 12928 KB Output is correct
30 Correct 9 ms 12928 KB Output is correct
31 Correct 10 ms 12928 KB Output is correct
32 Correct 10 ms 12960 KB Output is correct
33 Correct 10 ms 12928 KB Output is correct
34 Correct 10 ms 13056 KB Output is correct
35 Correct 10 ms 12928 KB Output is correct
36 Correct 10 ms 12928 KB Output is correct
37 Correct 10 ms 12928 KB Output is correct
38 Correct 10 ms 12928 KB Output is correct
39 Correct 346 ms 21344 KB Output is correct
40 Correct 340 ms 21368 KB Output is correct
41 Correct 321 ms 21368 KB Output is correct
42 Correct 289 ms 21364 KB Output is correct
43 Correct 245 ms 21676 KB Output is correct
44 Correct 121 ms 21496 KB Output is correct
45 Correct 271 ms 24056 KB Output is correct
46 Correct 139 ms 27112 KB Output is correct
47 Correct 371 ms 29560 KB Output is correct
48 Correct 1008 ms 41488 KB Output is correct
49 Correct 961 ms 40816 KB Output is correct
50 Correct 358 ms 29560 KB Output is correct
51 Correct 370 ms 29592 KB Output is correct
52 Correct 584 ms 29688 KB Output is correct
53 Correct 698 ms 28860 KB Output is correct
54 Correct 721 ms 29824 KB Output is correct
55 Correct 18 ms 13696 KB Output is correct
56 Correct 23 ms 13696 KB Output is correct
57 Correct 110 ms 21496 KB Output is correct
58 Correct 51 ms 20972 KB Output is correct
59 Correct 121 ms 27000 KB Output is correct
60 Correct 1014 ms 40976 KB Output is correct
61 Correct 373 ms 29816 KB Output is correct
62 Correct 345 ms 29560 KB Output is correct
63 Correct 580 ms 29692 KB Output is correct
64 Correct 1018 ms 30576 KB Output is correct
65 Correct 792 ms 31216 KB Output is correct
66 Correct 982 ms 38856 KB Output is correct
67 Correct 171 ms 30308 KB Output is correct
68 Correct 553 ms 30956 KB Output is correct
69 Correct 548 ms 31092 KB Output is correct
70 Correct 518 ms 30068 KB Output is correct