답안 #875888

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
875888 2023-11-20T17:12:52 Z hqminhuwu 경주 (Race) (IOI11_race) C++14
100 / 100
377 ms 112888 KB
#include <bits/stdc++.h>
#define forr(_a,_b,_c) for(_a = (_b); _a <= (_c); ++_a)
#define ford(_a,_b,_c) for(_a = (_b) + 1; _a --> (_c);)
#define forf(_a,_b,_c) for(_a = (_b); _a < (_c); ++_a)
#define st first
#define nd second
#define ll long long
#define ull unsigned long long
#define pii pair <int,int>
#define pll pair <int,ll>
#define piii pair <int,pii>
#define vi vector <int>
#define pb push_back
#define mp make_pair
#define all(x) begin(x),end(x)
#define file "test"
 
 
using namespace std;
const int N = 2e5 + 5;
const ll oo = 1e9;
const ll mod = 1e9 + 7;
 
map <int,ll> m[N];
vector <pll> a[N];
ll res, f[N], rk[N], dep[N];
ll k;
 
 
void dfs (int u, int p, ll c, int h) {
    m[u][c] = h;
	rk[u] = c;
	dep[u] = h;
	ll need = k + 2 * rk[u];
	for (pii v : a[u]) {
		if (v.st == p) continue;
		dfs (v.st, u, c + v.nd, h + 1);
		if (m[v.st].size() > m[u].size()) 
            swap(m[v.st], m[u]); 
 
		for (pll w : m[v.st]) 
			if (m[u].find(need - w.st) != m[u].end()) 
				res = min(res, m[u][need - w.st] + w.nd - 2 * dep[u]);
		
		for (pll w : m[v.st]) {
			if (m[u].find(w.st) == m[u].end()) 
				m[u].insert(w);
			 else  m[u][w.st] = min(m[u][w.st], w.nd);
		}
	}
}
int n,i,u,v,w;
int best_path (int nn, int kk, int edge[][2], int ww[]){
	res = oo;
    n = nn;
	k = kk;
    if (k == 1)
        return 0;
    forf (i,0,n - 1){
        u = edge[i][0];
		v = edge[i][1];
		w = ww[i];
        a[u].pb({v,w});
        a[v].pb({u,w});
    }
    dfs(0,0,0,0);
    return (res <= n - 1 ? res : -1);
}
 
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 20824 KB Output is correct
2 Correct 5 ms 20828 KB Output is correct
3 Correct 4 ms 20828 KB Output is correct
4 Correct 4 ms 20828 KB Output is correct
5 Correct 4 ms 20828 KB Output is correct
6 Correct 4 ms 20796 KB Output is correct
7 Correct 4 ms 20828 KB Output is correct
8 Correct 4 ms 20828 KB Output is correct
9 Correct 4 ms 20824 KB Output is correct
10 Correct 4 ms 20828 KB Output is correct
11 Correct 4 ms 20828 KB Output is correct
12 Correct 4 ms 20856 KB Output is correct
13 Correct 4 ms 20828 KB Output is correct
14 Correct 5 ms 20824 KB Output is correct
15 Correct 5 ms 20828 KB Output is correct
16 Correct 4 ms 20824 KB Output is correct
17 Correct 4 ms 20824 KB Output is correct
18 Correct 4 ms 20828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 20824 KB Output is correct
2 Correct 5 ms 20828 KB Output is correct
3 Correct 4 ms 20828 KB Output is correct
4 Correct 4 ms 20828 KB Output is correct
5 Correct 4 ms 20828 KB Output is correct
6 Correct 4 ms 20796 KB Output is correct
7 Correct 4 ms 20828 KB Output is correct
8 Correct 4 ms 20828 KB Output is correct
9 Correct 4 ms 20824 KB Output is correct
10 Correct 4 ms 20828 KB Output is correct
11 Correct 4 ms 20828 KB Output is correct
12 Correct 4 ms 20856 KB Output is correct
13 Correct 4 ms 20828 KB Output is correct
14 Correct 5 ms 20824 KB Output is correct
15 Correct 5 ms 20828 KB Output is correct
16 Correct 4 ms 20824 KB Output is correct
17 Correct 4 ms 20824 KB Output is correct
18 Correct 4 ms 20828 KB Output is correct
19 Correct 4 ms 20828 KB Output is correct
20 Correct 4 ms 20828 KB Output is correct
21 Correct 5 ms 20924 KB Output is correct
22 Correct 5 ms 21084 KB Output is correct
23 Correct 5 ms 21084 KB Output is correct
24 Correct 5 ms 21084 KB Output is correct
25 Correct 6 ms 21084 KB Output is correct
26 Correct 5 ms 21084 KB Output is correct
27 Correct 6 ms 20828 KB Output is correct
28 Correct 5 ms 21084 KB Output is correct
29 Correct 6 ms 21080 KB Output is correct
30 Correct 6 ms 21084 KB Output is correct
31 Correct 5 ms 21124 KB Output is correct
32 Correct 6 ms 21084 KB Output is correct
33 Correct 6 ms 21084 KB Output is correct
34 Correct 5 ms 21088 KB Output is correct
35 Correct 5 ms 21084 KB Output is correct
36 Correct 5 ms 20828 KB Output is correct
37 Correct 5 ms 20828 KB Output is correct
38 Correct 5 ms 21084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 20824 KB Output is correct
2 Correct 5 ms 20828 KB Output is correct
3 Correct 4 ms 20828 KB Output is correct
4 Correct 4 ms 20828 KB Output is correct
5 Correct 4 ms 20828 KB Output is correct
6 Correct 4 ms 20796 KB Output is correct
7 Correct 4 ms 20828 KB Output is correct
8 Correct 4 ms 20828 KB Output is correct
9 Correct 4 ms 20824 KB Output is correct
10 Correct 4 ms 20828 KB Output is correct
11 Correct 4 ms 20828 KB Output is correct
12 Correct 4 ms 20856 KB Output is correct
13 Correct 4 ms 20828 KB Output is correct
14 Correct 5 ms 20824 KB Output is correct
15 Correct 5 ms 20828 KB Output is correct
16 Correct 4 ms 20824 KB Output is correct
17 Correct 4 ms 20824 KB Output is correct
18 Correct 4 ms 20828 KB Output is correct
19 Correct 99 ms 44628 KB Output is correct
20 Correct 101 ms 44728 KB Output is correct
21 Correct 95 ms 44436 KB Output is correct
22 Correct 110 ms 44044 KB Output is correct
23 Correct 133 ms 56764 KB Output is correct
24 Correct 101 ms 46720 KB Output is correct
25 Correct 88 ms 45476 KB Output is correct
26 Correct 52 ms 53596 KB Output is correct
27 Correct 153 ms 56892 KB Output is correct
28 Correct 260 ms 98640 KB Output is correct
29 Correct 241 ms 96844 KB Output is correct
30 Correct 150 ms 56656 KB Output is correct
31 Correct 143 ms 56544 KB Output is correct
32 Correct 187 ms 56624 KB Output is correct
33 Correct 197 ms 61668 KB Output is correct
34 Correct 297 ms 93668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 20824 KB Output is correct
2 Correct 5 ms 20828 KB Output is correct
3 Correct 4 ms 20828 KB Output is correct
4 Correct 4 ms 20828 KB Output is correct
5 Correct 4 ms 20828 KB Output is correct
6 Correct 4 ms 20796 KB Output is correct
7 Correct 4 ms 20828 KB Output is correct
8 Correct 4 ms 20828 KB Output is correct
9 Correct 4 ms 20824 KB Output is correct
10 Correct 4 ms 20828 KB Output is correct
11 Correct 4 ms 20828 KB Output is correct
12 Correct 4 ms 20856 KB Output is correct
13 Correct 4 ms 20828 KB Output is correct
14 Correct 5 ms 20824 KB Output is correct
15 Correct 5 ms 20828 KB Output is correct
16 Correct 4 ms 20824 KB Output is correct
17 Correct 4 ms 20824 KB Output is correct
18 Correct 4 ms 20828 KB Output is correct
19 Correct 4 ms 20828 KB Output is correct
20 Correct 4 ms 20828 KB Output is correct
21 Correct 5 ms 20924 KB Output is correct
22 Correct 5 ms 21084 KB Output is correct
23 Correct 5 ms 21084 KB Output is correct
24 Correct 5 ms 21084 KB Output is correct
25 Correct 6 ms 21084 KB Output is correct
26 Correct 5 ms 21084 KB Output is correct
27 Correct 6 ms 20828 KB Output is correct
28 Correct 5 ms 21084 KB Output is correct
29 Correct 6 ms 21080 KB Output is correct
30 Correct 6 ms 21084 KB Output is correct
31 Correct 5 ms 21124 KB Output is correct
32 Correct 6 ms 21084 KB Output is correct
33 Correct 6 ms 21084 KB Output is correct
34 Correct 5 ms 21088 KB Output is correct
35 Correct 5 ms 21084 KB Output is correct
36 Correct 5 ms 20828 KB Output is correct
37 Correct 5 ms 20828 KB Output is correct
38 Correct 5 ms 21084 KB Output is correct
39 Correct 99 ms 44628 KB Output is correct
40 Correct 101 ms 44728 KB Output is correct
41 Correct 95 ms 44436 KB Output is correct
42 Correct 110 ms 44044 KB Output is correct
43 Correct 133 ms 56764 KB Output is correct
44 Correct 101 ms 46720 KB Output is correct
45 Correct 88 ms 45476 KB Output is correct
46 Correct 52 ms 53596 KB Output is correct
47 Correct 153 ms 56892 KB Output is correct
48 Correct 260 ms 98640 KB Output is correct
49 Correct 241 ms 96844 KB Output is correct
50 Correct 150 ms 56656 KB Output is correct
51 Correct 143 ms 56544 KB Output is correct
52 Correct 187 ms 56624 KB Output is correct
53 Correct 197 ms 61668 KB Output is correct
54 Correct 297 ms 93668 KB Output is correct
55 Correct 16 ms 23896 KB Output is correct
56 Correct 11 ms 22620 KB Output is correct
57 Correct 62 ms 42572 KB Output is correct
58 Correct 43 ms 34956 KB Output is correct
59 Correct 77 ms 60308 KB Output is correct
60 Correct 227 ms 98652 KB Output is correct
61 Correct 177 ms 61524 KB Output is correct
62 Correct 142 ms 57696 KB Output is correct
63 Correct 186 ms 57848 KB Output is correct
64 Correct 377 ms 112888 KB Output is correct
65 Correct 357 ms 110644 KB Output is correct
66 Correct 272 ms 93956 KB Output is correct
67 Correct 138 ms 51380 KB Output is correct
68 Correct 283 ms 74360 KB Output is correct
69 Correct 302 ms 78928 KB Output is correct
70 Correct 279 ms 71980 KB Output is correct