답안 #748591

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
748591 2023-05-26T14:42:26 Z ZeroCool 경주 (Race) (IOI11_race) C++17
100 / 100
397 ms 108108 KB
#include "race.h"
#include <bits/stdc++.h>
#define ll long long


const int mxn = 200005;
const int inf = 1e9;

using namespace std;
set<pair<ll,int> > s[mxn];
vector<pair<int,int> > g[mxn];

int n,k;

int ans;

void dfs(int x,int p,ll dis,int dep){
	s[x].insert({dis,dep});
	for(auto par : g[x]){
		int y = par.first;
		int z = par.second;
		if(y == p)continue;

		dfs(y,x,dis+z,dep+1);

		if(s[x].size() < s[y].size())swap(s[x],s[y]);

		for(auto par2 : s[y]){
			int len= par2.first;
			int cnt = par2.second;

			ll q = k - len + 2*dis;

			auto it = s[x].lower_bound({q,0});

			if(it != s[x].end() && (*it).first == q){
				ans = min(ans, (*it).second + cnt - 2 * dep);
			}
		}
		s[x].insert(s[y].begin(),s[y].end());
	}
}


int best_path(int _n, int _k, int H[][2], int L[]){
	n = _n;
	k = _k;
	//vector<vector<pair<int, int>>> g(n);
    for (int i = 0; i < n - 1; i++) {
        g[H[i][0]].push_back({H[i][1], L[i]});
        g[H[i][1]].push_back({H[i][0], L[i]});
    }
    ans = n;

    //vector<set<pair<ll, int>>> s(n);

    // auto dfs = [&](auto dfs, int x, int p, ll dis, int dep) -> void {
    //     //s[x].emplace(dis, dep);
	// 	s[x].insert({dis,dep});
    //     for (auto [y,z] : g[x]) {
	// 		if (y == p) continue;
            
    //         dfs(dfs, y, x, dis + z, dep + 1);

    //         if (s[x].size() < s[y].size()) {
    //             swap(s[x], s[y]);
    //         }

    //         for (auto [len, cnt] : s[y]) {
    //             ll q = k - len + 2 * dis;
    //             auto it = s[x].lower_bound({q, 0});
    //             if (it != s[x].end() && (*it).first == q) {
    //                 ans = min(ans, (*it).second + cnt - 2 * dep);
    //             }
    //         }
    //         s[x].insert(s[y].begin(), s[y].end());
    //     }
    // };
    dfs( 0, -1, 0, 0);
    if (ans == n) {
        ans = -1;
    }
    return ans;

}	
//Pls work
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14404 KB Output is correct
3 Correct 9 ms 14376 KB Output is correct
4 Correct 7 ms 14400 KB Output is correct
5 Correct 7 ms 14420 KB Output is correct
6 Correct 8 ms 14420 KB Output is correct
7 Correct 8 ms 14420 KB Output is correct
8 Correct 8 ms 14400 KB Output is correct
9 Correct 8 ms 14420 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 8 ms 14420 KB Output is correct
12 Correct 8 ms 14396 KB Output is correct
13 Correct 7 ms 14404 KB Output is correct
14 Correct 7 ms 14400 KB Output is correct
15 Correct 8 ms 14324 KB Output is correct
16 Correct 8 ms 14420 KB Output is correct
17 Correct 8 ms 14420 KB Output is correct
18 Correct 7 ms 14420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14404 KB Output is correct
3 Correct 9 ms 14376 KB Output is correct
4 Correct 7 ms 14400 KB Output is correct
5 Correct 7 ms 14420 KB Output is correct
6 Correct 8 ms 14420 KB Output is correct
7 Correct 8 ms 14420 KB Output is correct
8 Correct 8 ms 14400 KB Output is correct
9 Correct 8 ms 14420 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 8 ms 14420 KB Output is correct
12 Correct 8 ms 14396 KB Output is correct
13 Correct 7 ms 14404 KB Output is correct
14 Correct 7 ms 14400 KB Output is correct
15 Correct 8 ms 14324 KB Output is correct
16 Correct 8 ms 14420 KB Output is correct
17 Correct 8 ms 14420 KB Output is correct
18 Correct 7 ms 14420 KB Output is correct
19 Correct 8 ms 14400 KB Output is correct
20 Correct 7 ms 14420 KB Output is correct
21 Correct 9 ms 14660 KB Output is correct
22 Correct 9 ms 14676 KB Output is correct
23 Correct 11 ms 14664 KB Output is correct
24 Correct 8 ms 14628 KB Output is correct
25 Correct 9 ms 14592 KB Output is correct
26 Correct 8 ms 14676 KB Output is correct
27 Correct 8 ms 14536 KB Output is correct
28 Correct 8 ms 14620 KB Output is correct
29 Correct 9 ms 14676 KB Output is correct
30 Correct 9 ms 14676 KB Output is correct
31 Correct 8 ms 14676 KB Output is correct
32 Correct 8 ms 14676 KB Output is correct
33 Correct 11 ms 14668 KB Output is correct
34 Correct 8 ms 14548 KB Output is correct
35 Correct 8 ms 14548 KB Output is correct
36 Correct 8 ms 14540 KB Output is correct
37 Correct 8 ms 14532 KB Output is correct
38 Correct 8 ms 14644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14404 KB Output is correct
3 Correct 9 ms 14376 KB Output is correct
4 Correct 7 ms 14400 KB Output is correct
5 Correct 7 ms 14420 KB Output is correct
6 Correct 8 ms 14420 KB Output is correct
7 Correct 8 ms 14420 KB Output is correct
8 Correct 8 ms 14400 KB Output is correct
9 Correct 8 ms 14420 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 8 ms 14420 KB Output is correct
12 Correct 8 ms 14396 KB Output is correct
13 Correct 7 ms 14404 KB Output is correct
14 Correct 7 ms 14400 KB Output is correct
15 Correct 8 ms 14324 KB Output is correct
16 Correct 8 ms 14420 KB Output is correct
17 Correct 8 ms 14420 KB Output is correct
18 Correct 7 ms 14420 KB Output is correct
19 Correct 132 ms 41016 KB Output is correct
20 Correct 131 ms 40912 KB Output is correct
21 Correct 135 ms 40284 KB Output is correct
22 Correct 134 ms 39036 KB Output is correct
23 Correct 161 ms 53356 KB Output is correct
24 Correct 123 ms 39988 KB Output is correct
25 Correct 119 ms 43724 KB Output is correct
26 Correct 85 ms 48204 KB Output is correct
27 Correct 186 ms 49400 KB Output is correct
28 Correct 271 ms 82292 KB Output is correct
29 Correct 249 ms 80924 KB Output is correct
30 Correct 188 ms 49412 KB Output is correct
31 Correct 188 ms 49224 KB Output is correct
32 Correct 239 ms 49596 KB Output is correct
33 Correct 203 ms 51144 KB Output is correct
34 Correct 297 ms 84144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14404 KB Output is correct
3 Correct 9 ms 14376 KB Output is correct
4 Correct 7 ms 14400 KB Output is correct
5 Correct 7 ms 14420 KB Output is correct
6 Correct 8 ms 14420 KB Output is correct
7 Correct 8 ms 14420 KB Output is correct
8 Correct 8 ms 14400 KB Output is correct
9 Correct 8 ms 14420 KB Output is correct
10 Correct 7 ms 14420 KB Output is correct
11 Correct 8 ms 14420 KB Output is correct
12 Correct 8 ms 14396 KB Output is correct
13 Correct 7 ms 14404 KB Output is correct
14 Correct 7 ms 14400 KB Output is correct
15 Correct 8 ms 14324 KB Output is correct
16 Correct 8 ms 14420 KB Output is correct
17 Correct 8 ms 14420 KB Output is correct
18 Correct 7 ms 14420 KB Output is correct
19 Correct 8 ms 14400 KB Output is correct
20 Correct 7 ms 14420 KB Output is correct
21 Correct 9 ms 14660 KB Output is correct
22 Correct 9 ms 14676 KB Output is correct
23 Correct 11 ms 14664 KB Output is correct
24 Correct 8 ms 14628 KB Output is correct
25 Correct 9 ms 14592 KB Output is correct
26 Correct 8 ms 14676 KB Output is correct
27 Correct 8 ms 14536 KB Output is correct
28 Correct 8 ms 14620 KB Output is correct
29 Correct 9 ms 14676 KB Output is correct
30 Correct 9 ms 14676 KB Output is correct
31 Correct 8 ms 14676 KB Output is correct
32 Correct 8 ms 14676 KB Output is correct
33 Correct 11 ms 14668 KB Output is correct
34 Correct 8 ms 14548 KB Output is correct
35 Correct 8 ms 14548 KB Output is correct
36 Correct 8 ms 14540 KB Output is correct
37 Correct 8 ms 14532 KB Output is correct
38 Correct 8 ms 14644 KB Output is correct
39 Correct 132 ms 41016 KB Output is correct
40 Correct 131 ms 40912 KB Output is correct
41 Correct 135 ms 40284 KB Output is correct
42 Correct 134 ms 39036 KB Output is correct
43 Correct 161 ms 53356 KB Output is correct
44 Correct 123 ms 39988 KB Output is correct
45 Correct 119 ms 43724 KB Output is correct
46 Correct 85 ms 48204 KB Output is correct
47 Correct 186 ms 49400 KB Output is correct
48 Correct 271 ms 82292 KB Output is correct
49 Correct 249 ms 80924 KB Output is correct
50 Correct 188 ms 49412 KB Output is correct
51 Correct 188 ms 49224 KB Output is correct
52 Correct 239 ms 49596 KB Output is correct
53 Correct 203 ms 51144 KB Output is correct
54 Correct 297 ms 84144 KB Output is correct
55 Correct 20 ms 17828 KB Output is correct
56 Correct 15 ms 16452 KB Output is correct
57 Correct 85 ms 35660 KB Output is correct
58 Correct 50 ms 26724 KB Output is correct
59 Correct 80 ms 48132 KB Output is correct
60 Correct 266 ms 81488 KB Output is correct
61 Correct 239 ms 55228 KB Output is correct
62 Correct 197 ms 49408 KB Output is correct
63 Correct 231 ms 49476 KB Output is correct
64 Correct 391 ms 108108 KB Output is correct
65 Correct 397 ms 99840 KB Output is correct
66 Correct 255 ms 77984 KB Output is correct
67 Correct 156 ms 40724 KB Output is correct
68 Correct 309 ms 64992 KB Output is correct
69 Correct 324 ms 70608 KB Output is correct
70 Correct 292 ms 63012 KB Output is correct