답안 #418831

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
418831 2021-06-06T02:33:21 Z Maqsut_03 경주 (Race) (IOI11_race) C++14
100 / 100
1357 ms 51408 KB
#include "race.h"
#include <bits/stdc++.h>
 
#define N 200200
using namespace std;
 
vector<pair<int, int> > g[N];
int d[N];
//int p[N];
 
int get_centroid(int v, int parent, int n, int &centroid) {
    int size = 1;
    for (auto[x, y]:g[v]) {
        if (x != parent && d[x] == -1) {
            size += get_centroid(x, v, n, centroid);
        }
    }
    if (size * 2 >= n && centroid == -1) centroid = v;
    return size;
}
 
int K;
int ans = 1e9;
 
void get_compo_dists(int v, int dist, int len, int pass_limit, vector<pair<int, int> > &vec, int p = -1) 
{
    if (dist > K) return;
    vec.emplace_back(dist, len);
    
    for (auto[x, y]:g[v]) 
        if ((d[x] > pass_limit || d[x] == -1) && p != x) 
            get_compo_dists(x, dist + y, len + 1, pass_limit, vec, v);
}
 
void build(int v, int parent, int depth, int n) 
{
    int centroid = -1;
    get_centroid(v, -1, n, centroid);
    if (centroid == -1) centroid = v;
    d[centroid] = depth;
//    p[centroid] = parent;
    map<int, int> dist;
    dist[0] = 0;
 
    for (auto[x, y]:g[centroid]) 
        if (d[x] == -1) 
		{
            vector<pair<int, int>> vec;
            get_compo_dists(x, y, 1, d[centroid], vec);
            
			for (auto[distance, cost]: vec) 
                if (dist.count(K - distance)) 
                    ans = min(ans, cost + dist[K - distance]);
 
            for (auto[distance, cost]: vec)
                if (dist.count(distance) == 0) 
                    dist[distance] = cost;
				else dist[distance] = min(dist[distance], cost);
            
			build(x, centroid, depth + 1, (n + 1) / 2);
        }
}
 
int best_path(int n, int K, int H[][2], int L[]) 
{
    ::K = K;
    for (int i = 0; i < n - 1; i++)
	{
        g[H[i][0]].emplace_back(H[i][1], L[i]);
        g[H[i][1]].emplace_back(H[i][0], L[i]);
    }
    fill(d, d + N, -1);
    build(0, -1, 1, n);
 
    return (ans == 1e9 ? -1 : ans);
}
 

Compilation message

race.cpp: In function 'int get_centroid(int, int, int, int&)':
race.cpp:13:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   13 |     for (auto[x, y]:g[v]) {
      |              ^
race.cpp: In function 'void get_compo_dists(int, int, int, int, std::vector<std::pair<int, int> >&, int)':
race.cpp:30:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   30 |     for (auto[x, y]:g[v])
      |              ^
race.cpp: In function 'void build(int, int, int, int)':
race.cpp:45:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   45 |     for (auto[x, y]:g[centroid])
      |              ^
race.cpp:51:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   51 |    for (auto[distance, cost]: vec)
      |             ^
race.cpp:55:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   55 |             for (auto[distance, cost]: vec)
      |                      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5708 KB Output is correct
2 Correct 4 ms 5776 KB Output is correct
3 Correct 3 ms 5708 KB Output is correct
4 Correct 3 ms 5708 KB Output is correct
5 Correct 3 ms 5720 KB Output is correct
6 Correct 4 ms 5772 KB Output is correct
7 Correct 3 ms 5708 KB Output is correct
8 Correct 4 ms 5772 KB Output is correct
9 Correct 4 ms 5708 KB Output is correct
10 Correct 3 ms 5768 KB Output is correct
11 Correct 4 ms 5708 KB Output is correct
12 Correct 3 ms 5708 KB Output is correct
13 Correct 3 ms 5708 KB Output is correct
14 Correct 4 ms 5808 KB Output is correct
15 Correct 5 ms 5772 KB Output is correct
16 Correct 4 ms 5772 KB Output is correct
17 Correct 3 ms 5708 KB Output is correct
18 Correct 4 ms 5708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5708 KB Output is correct
2 Correct 4 ms 5776 KB Output is correct
3 Correct 3 ms 5708 KB Output is correct
4 Correct 3 ms 5708 KB Output is correct
5 Correct 3 ms 5720 KB Output is correct
6 Correct 4 ms 5772 KB Output is correct
7 Correct 3 ms 5708 KB Output is correct
8 Correct 4 ms 5772 KB Output is correct
9 Correct 4 ms 5708 KB Output is correct
10 Correct 3 ms 5768 KB Output is correct
11 Correct 4 ms 5708 KB Output is correct
12 Correct 3 ms 5708 KB Output is correct
13 Correct 3 ms 5708 KB Output is correct
14 Correct 4 ms 5808 KB Output is correct
15 Correct 5 ms 5772 KB Output is correct
16 Correct 4 ms 5772 KB Output is correct
17 Correct 3 ms 5708 KB Output is correct
18 Correct 4 ms 5708 KB Output is correct
19 Correct 3 ms 5780 KB Output is correct
20 Correct 3 ms 5708 KB Output is correct
21 Correct 5 ms 5776 KB Output is correct
22 Correct 4 ms 5836 KB Output is correct
23 Correct 5 ms 5836 KB Output is correct
24 Correct 6 ms 5784 KB Output is correct
25 Correct 6 ms 5836 KB Output is correct
26 Correct 5 ms 5836 KB Output is correct
27 Correct 4 ms 5836 KB Output is correct
28 Correct 5 ms 5836 KB Output is correct
29 Correct 5 ms 5836 KB Output is correct
30 Correct 5 ms 5908 KB Output is correct
31 Correct 7 ms 5908 KB Output is correct
32 Correct 5 ms 5836 KB Output is correct
33 Correct 6 ms 5908 KB Output is correct
34 Correct 5 ms 5836 KB Output is correct
35 Correct 5 ms 5836 KB Output is correct
36 Correct 5 ms 5836 KB Output is correct
37 Correct 5 ms 5836 KB Output is correct
38 Correct 5 ms 5836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5708 KB Output is correct
2 Correct 4 ms 5776 KB Output is correct
3 Correct 3 ms 5708 KB Output is correct
4 Correct 3 ms 5708 KB Output is correct
5 Correct 3 ms 5720 KB Output is correct
6 Correct 4 ms 5772 KB Output is correct
7 Correct 3 ms 5708 KB Output is correct
8 Correct 4 ms 5772 KB Output is correct
9 Correct 4 ms 5708 KB Output is correct
10 Correct 3 ms 5768 KB Output is correct
11 Correct 4 ms 5708 KB Output is correct
12 Correct 3 ms 5708 KB Output is correct
13 Correct 3 ms 5708 KB Output is correct
14 Correct 4 ms 5808 KB Output is correct
15 Correct 5 ms 5772 KB Output is correct
16 Correct 4 ms 5772 KB Output is correct
17 Correct 3 ms 5708 KB Output is correct
18 Correct 4 ms 5708 KB Output is correct
19 Correct 292 ms 12284 KB Output is correct
20 Correct 283 ms 12216 KB Output is correct
21 Correct 305 ms 12532 KB Output is correct
22 Correct 270 ms 12808 KB Output is correct
23 Correct 103 ms 12212 KB Output is correct
24 Correct 96 ms 12212 KB Output is correct
25 Correct 184 ms 15564 KB Output is correct
26 Correct 134 ms 20132 KB Output is correct
27 Correct 275 ms 18636 KB Output is correct
28 Correct 306 ms 33052 KB Output is correct
29 Correct 275 ms 31932 KB Output is correct
30 Correct 258 ms 18648 KB Output is correct
31 Correct 274 ms 18744 KB Output is correct
32 Correct 303 ms 18744 KB Output is correct
33 Correct 364 ms 17616 KB Output is correct
34 Correct 204 ms 18404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5708 KB Output is correct
2 Correct 4 ms 5776 KB Output is correct
3 Correct 3 ms 5708 KB Output is correct
4 Correct 3 ms 5708 KB Output is correct
5 Correct 3 ms 5720 KB Output is correct
6 Correct 4 ms 5772 KB Output is correct
7 Correct 3 ms 5708 KB Output is correct
8 Correct 4 ms 5772 KB Output is correct
9 Correct 4 ms 5708 KB Output is correct
10 Correct 3 ms 5768 KB Output is correct
11 Correct 4 ms 5708 KB Output is correct
12 Correct 3 ms 5708 KB Output is correct
13 Correct 3 ms 5708 KB Output is correct
14 Correct 4 ms 5808 KB Output is correct
15 Correct 5 ms 5772 KB Output is correct
16 Correct 4 ms 5772 KB Output is correct
17 Correct 3 ms 5708 KB Output is correct
18 Correct 4 ms 5708 KB Output is correct
19 Correct 3 ms 5780 KB Output is correct
20 Correct 3 ms 5708 KB Output is correct
21 Correct 5 ms 5776 KB Output is correct
22 Correct 4 ms 5836 KB Output is correct
23 Correct 5 ms 5836 KB Output is correct
24 Correct 6 ms 5784 KB Output is correct
25 Correct 6 ms 5836 KB Output is correct
26 Correct 5 ms 5836 KB Output is correct
27 Correct 4 ms 5836 KB Output is correct
28 Correct 5 ms 5836 KB Output is correct
29 Correct 5 ms 5836 KB Output is correct
30 Correct 5 ms 5908 KB Output is correct
31 Correct 7 ms 5908 KB Output is correct
32 Correct 5 ms 5836 KB Output is correct
33 Correct 6 ms 5908 KB Output is correct
34 Correct 5 ms 5836 KB Output is correct
35 Correct 5 ms 5836 KB Output is correct
36 Correct 5 ms 5836 KB Output is correct
37 Correct 5 ms 5836 KB Output is correct
38 Correct 5 ms 5836 KB Output is correct
39 Correct 292 ms 12284 KB Output is correct
40 Correct 283 ms 12216 KB Output is correct
41 Correct 305 ms 12532 KB Output is correct
42 Correct 270 ms 12808 KB Output is correct
43 Correct 103 ms 12212 KB Output is correct
44 Correct 96 ms 12212 KB Output is correct
45 Correct 184 ms 15564 KB Output is correct
46 Correct 134 ms 20132 KB Output is correct
47 Correct 275 ms 18636 KB Output is correct
48 Correct 306 ms 33052 KB Output is correct
49 Correct 275 ms 31932 KB Output is correct
50 Correct 258 ms 18648 KB Output is correct
51 Correct 274 ms 18744 KB Output is correct
52 Correct 303 ms 18744 KB Output is correct
53 Correct 364 ms 17616 KB Output is correct
54 Correct 204 ms 18404 KB Output is correct
55 Correct 28 ms 6708 KB Output is correct
56 Correct 22 ms 6476 KB Output is correct
57 Correct 174 ms 12928 KB Output is correct
58 Correct 55 ms 11832 KB Output is correct
59 Correct 412 ms 27264 KB Output is correct
60 Correct 1041 ms 51408 KB Output is correct
61 Correct 434 ms 19164 KB Output is correct
62 Correct 621 ms 19152 KB Output is correct
63 Correct 670 ms 19100 KB Output is correct
64 Correct 1357 ms 30304 KB Output is correct
65 Correct 324 ms 19476 KB Output is correct
66 Correct 756 ms 31044 KB Output is correct
67 Correct 198 ms 19348 KB Output is correct
68 Correct 875 ms 23504 KB Output is correct
69 Correct 825 ms 23504 KB Output is correct
70 Correct 855 ms 22716 KB Output is correct