답안 #923846

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
923846 2024-02-08T02:23:51 Z Whisper 경주 (Race) (IOI11_race) C++17
100 / 100
774 ms 38452 KB
#include "race.h"
//~ #include "grader.cpp"
#include <bits/stdc++.h>
 
using namespace std;
 
#define pb push_back
#define ff first
#define ss second
 
typedef vector<int> vi;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<vi> vv;
const int inf = 1e9, mxN = 2e5+2;
 
vii g[mxN];
int us[mxN];
int m, ctr, ans = inf;
int k;
map<int,int> mp;
int dfs_sz(int v, int pr){
	if(us[v])return 0;
	int s = 1;
	for(auto [to, cst]:g[v]){
		if(to == pr)continue;
		s += dfs_sz(to, v);
	}
	return s;
}
int dfs_ctr(int v, int pr){
	if(us[v])return 0;
	int s = 1;
	bool ok = 1;
	for(auto [to, cst]:g[v]){
		if(to == pr)continue;
		int sto = dfs_ctr(to, v);
		if(sto > m/2)ok = 0;
		s += sto;
	}
	if(s < m/2)ok = 0;
	if(ok)ctr = v;
	return s;
}
void dfs(int v, int pr, int dep, int sum, bool ok){
	if(sum > k)return;
    if (!ok){
        if ( sum == k ) ans = min(ans, dep);
        else ans = min(ans, !mp.count(k-sum) ? inf : mp[k-sum]+dep);
    }else{
        if ( !mp.count(sum) ) mp[sum] = dep;
        else mp[sum] = min(mp[sum], dep);
    }
    for(auto [to, w]:g[v]){
        if (us[to] || to == pr)continue;
        dfs(to, v, dep+1, sum+w, ok);
    }
}
void fun(int v){
	m = dfs_sz(v, -1);
	m = dfs_ctr(v, -1);
	us[ctr] = 1;
	mp.clear();
	for(auto [to, cst]:g[ctr]){
		if(us[to])continue;
		dfs(to, ctr, 1, cst, 0);
		dfs(to, ctr, 1, cst, 1);
	}
	for(auto [to, cst]:g[ctr]){
		if(us[to])continue;
		fun(to);
	}
}
int best_path(int n, int K, int h[][2], int l[])
{
	for(int i = 0; i < n-1; i++){
		g[h[i][0]].pb({h[i][1], l[i]});
		g[h[i][1]].pb({h[i][0], l[i]});
	}
	k = K;
	fun(0);
	return (ans == inf?-1:ans);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9564 KB Output is correct
2 Correct 2 ms 9564 KB Output is correct
3 Correct 2 ms 9564 KB Output is correct
4 Correct 2 ms 9560 KB Output is correct
5 Correct 2 ms 9564 KB Output is correct
6 Correct 2 ms 9564 KB Output is correct
7 Correct 2 ms 9564 KB Output is correct
8 Correct 2 ms 9564 KB Output is correct
9 Correct 2 ms 9560 KB Output is correct
10 Correct 2 ms 9564 KB Output is correct
11 Correct 2 ms 9564 KB Output is correct
12 Correct 2 ms 9564 KB Output is correct
13 Correct 2 ms 9564 KB Output is correct
14 Correct 2 ms 9564 KB Output is correct
15 Correct 2 ms 9572 KB Output is correct
16 Correct 2 ms 9564 KB Output is correct
17 Correct 2 ms 9560 KB Output is correct
18 Correct 3 ms 9560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9564 KB Output is correct
2 Correct 2 ms 9564 KB Output is correct
3 Correct 2 ms 9564 KB Output is correct
4 Correct 2 ms 9560 KB Output is correct
5 Correct 2 ms 9564 KB Output is correct
6 Correct 2 ms 9564 KB Output is correct
7 Correct 2 ms 9564 KB Output is correct
8 Correct 2 ms 9564 KB Output is correct
9 Correct 2 ms 9560 KB Output is correct
10 Correct 2 ms 9564 KB Output is correct
11 Correct 2 ms 9564 KB Output is correct
12 Correct 2 ms 9564 KB Output is correct
13 Correct 2 ms 9564 KB Output is correct
14 Correct 2 ms 9564 KB Output is correct
15 Correct 2 ms 9572 KB Output is correct
16 Correct 2 ms 9564 KB Output is correct
17 Correct 2 ms 9560 KB Output is correct
18 Correct 3 ms 9560 KB Output is correct
19 Correct 2 ms 9816 KB Output is correct
20 Correct 2 ms 9564 KB Output is correct
21 Correct 3 ms 9564 KB Output is correct
22 Correct 3 ms 9488 KB Output is correct
23 Correct 2 ms 9564 KB Output is correct
24 Correct 3 ms 9564 KB Output is correct
25 Correct 3 ms 9564 KB Output is correct
26 Correct 2 ms 9564 KB Output is correct
27 Correct 2 ms 9564 KB Output is correct
28 Correct 3 ms 9816 KB Output is correct
29 Correct 3 ms 9560 KB Output is correct
30 Correct 3 ms 9564 KB Output is correct
31 Correct 3 ms 9564 KB Output is correct
32 Correct 3 ms 9564 KB Output is correct
33 Correct 3 ms 9564 KB Output is correct
34 Correct 3 ms 9564 KB Output is correct
35 Correct 3 ms 9564 KB Output is correct
36 Correct 2 ms 9564 KB Output is correct
37 Correct 3 ms 9560 KB Output is correct
38 Correct 3 ms 9564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9564 KB Output is correct
2 Correct 2 ms 9564 KB Output is correct
3 Correct 2 ms 9564 KB Output is correct
4 Correct 2 ms 9560 KB Output is correct
5 Correct 2 ms 9564 KB Output is correct
6 Correct 2 ms 9564 KB Output is correct
7 Correct 2 ms 9564 KB Output is correct
8 Correct 2 ms 9564 KB Output is correct
9 Correct 2 ms 9560 KB Output is correct
10 Correct 2 ms 9564 KB Output is correct
11 Correct 2 ms 9564 KB Output is correct
12 Correct 2 ms 9564 KB Output is correct
13 Correct 2 ms 9564 KB Output is correct
14 Correct 2 ms 9564 KB Output is correct
15 Correct 2 ms 9572 KB Output is correct
16 Correct 2 ms 9564 KB Output is correct
17 Correct 2 ms 9560 KB Output is correct
18 Correct 3 ms 9560 KB Output is correct
19 Correct 145 ms 15364 KB Output is correct
20 Correct 149 ms 15416 KB Output is correct
21 Correct 162 ms 15700 KB Output is correct
22 Correct 141 ms 15448 KB Output is correct
23 Correct 62 ms 15440 KB Output is correct
24 Correct 52 ms 15532 KB Output is correct
25 Correct 113 ms 18252 KB Output is correct
26 Correct 88 ms 21084 KB Output is correct
27 Correct 138 ms 19284 KB Output is correct
28 Correct 182 ms 30468 KB Output is correct
29 Correct 185 ms 29780 KB Output is correct
30 Correct 137 ms 19284 KB Output is correct
31 Correct 137 ms 19348 KB Output is correct
32 Correct 152 ms 19280 KB Output is correct
33 Correct 202 ms 18004 KB Output is correct
34 Correct 131 ms 18000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9564 KB Output is correct
2 Correct 2 ms 9564 KB Output is correct
3 Correct 2 ms 9564 KB Output is correct
4 Correct 2 ms 9560 KB Output is correct
5 Correct 2 ms 9564 KB Output is correct
6 Correct 2 ms 9564 KB Output is correct
7 Correct 2 ms 9564 KB Output is correct
8 Correct 2 ms 9564 KB Output is correct
9 Correct 2 ms 9560 KB Output is correct
10 Correct 2 ms 9564 KB Output is correct
11 Correct 2 ms 9564 KB Output is correct
12 Correct 2 ms 9564 KB Output is correct
13 Correct 2 ms 9564 KB Output is correct
14 Correct 2 ms 9564 KB Output is correct
15 Correct 2 ms 9572 KB Output is correct
16 Correct 2 ms 9564 KB Output is correct
17 Correct 2 ms 9560 KB Output is correct
18 Correct 3 ms 9560 KB Output is correct
19 Correct 2 ms 9816 KB Output is correct
20 Correct 2 ms 9564 KB Output is correct
21 Correct 3 ms 9564 KB Output is correct
22 Correct 3 ms 9488 KB Output is correct
23 Correct 2 ms 9564 KB Output is correct
24 Correct 3 ms 9564 KB Output is correct
25 Correct 3 ms 9564 KB Output is correct
26 Correct 2 ms 9564 KB Output is correct
27 Correct 2 ms 9564 KB Output is correct
28 Correct 3 ms 9816 KB Output is correct
29 Correct 3 ms 9560 KB Output is correct
30 Correct 3 ms 9564 KB Output is correct
31 Correct 3 ms 9564 KB Output is correct
32 Correct 3 ms 9564 KB Output is correct
33 Correct 3 ms 9564 KB Output is correct
34 Correct 3 ms 9564 KB Output is correct
35 Correct 3 ms 9564 KB Output is correct
36 Correct 2 ms 9564 KB Output is correct
37 Correct 3 ms 9560 KB Output is correct
38 Correct 3 ms 9564 KB Output is correct
39 Correct 145 ms 15364 KB Output is correct
40 Correct 149 ms 15416 KB Output is correct
41 Correct 162 ms 15700 KB Output is correct
42 Correct 141 ms 15448 KB Output is correct
43 Correct 62 ms 15440 KB Output is correct
44 Correct 52 ms 15532 KB Output is correct
45 Correct 113 ms 18252 KB Output is correct
46 Correct 88 ms 21084 KB Output is correct
47 Correct 138 ms 19284 KB Output is correct
48 Correct 182 ms 30468 KB Output is correct
49 Correct 185 ms 29780 KB Output is correct
50 Correct 137 ms 19284 KB Output is correct
51 Correct 137 ms 19348 KB Output is correct
52 Correct 152 ms 19280 KB Output is correct
53 Correct 202 ms 18004 KB Output is correct
54 Correct 131 ms 18000 KB Output is correct
55 Correct 15 ms 10072 KB Output is correct
56 Correct 13 ms 9820 KB Output is correct
57 Correct 124 ms 15772 KB Output is correct
58 Correct 36 ms 15564 KB Output is correct
59 Correct 232 ms 24672 KB Output is correct
60 Correct 652 ms 38452 KB Output is correct
61 Correct 199 ms 19484 KB Output is correct
62 Correct 225 ms 19540 KB Output is correct
63 Correct 255 ms 19592 KB Output is correct
64 Correct 774 ms 23632 KB Output is correct
65 Correct 143 ms 19248 KB Output is correct
66 Correct 415 ms 27500 KB Output is correct
67 Correct 87 ms 19392 KB Output is correct
68 Correct 288 ms 23020 KB Output is correct
69 Correct 312 ms 23144 KB Output is correct
70 Correct 260 ms 22564 KB Output is correct