# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
797773 | 2023-07-29T21:34:44 Z | ttamx | 경주 (Race) (IOI11_race) | C++14 | 221 ms | 35084 KB |
#include "race.h" #include<bits/stdc++.h> using namespace std; typedef pair<int,int> p2; const int N=2e5+5; const int K=1e6+5; int n,k; int ans; vector<p2> adj[N]; int sz[N]; bool used[N]; int dist[K]; vector<int> res; vector<p2> res2; int dfssz(int u,int p=-1){ sz[u]=1; for(auto [v,w]:adj[u])if(v!=p&&!used[v])sz[u]+=dfssz(v,u); return sz[u]; } int centroid(int u,int cnt,int p=-1){ for(auto [v,w]:adj[u])if(v!=p&&!used[v]&&sz[v]*2>cnt)return centroid(v,cnt,u); return u; } void dfs(int u,int d,int cnt,int p=-1){ if(d>k)return; res.emplace_back(d); res2.emplace_back(d,cnt); ans=min(ans,cnt+dist[k-d]); for(auto [v,w]:adj[u])if(v!=p&&!used[v])dfs(v,d+w,cnt+1,u); } void decom(int u){ u=centroid(u,dfssz(u)); used[u]=true; for(auto [v,w]:adj[u]){ if(used[v])continue; dfs(v,w,1,u); for(auto [x,y]:res2)dist[x]=min(dist[x],y); res2.clear(); } for(auto i:res)dist[i]=n; res.clear(); for(auto [v,w]:adj[u])if(!used[v])decom(v); } int best_path(int N, int K, int H[][2], int L[]){ n=N,k=K; ans=n; for(int i=1;i<=k;i++)dist[i]=n; for(int i=0;i<n-1;i++){ int u=H[i][0],v=H[i][1],w=L[i]; adj[u].emplace_back(v,w); adj[v].emplace_back(u,w); } decom(0); return (ans==n?-1:ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 4948 KB | Output is correct |
2 | Correct | 4 ms | 4948 KB | Output is correct |
3 | Correct | 3 ms | 4948 KB | Output is correct |
4 | Correct | 2 ms | 4948 KB | Output is correct |
5 | Correct | 2 ms | 4948 KB | Output is correct |
6 | Correct | 2 ms | 4948 KB | Output is correct |
7 | Correct | 2 ms | 5012 KB | Output is correct |
8 | Correct | 2 ms | 4948 KB | Output is correct |
9 | Correct | 2 ms | 4948 KB | Output is correct |
10 | Correct | 2 ms | 4948 KB | Output is correct |
11 | Correct | 3 ms | 5016 KB | Output is correct |
12 | Correct | 2 ms | 5016 KB | Output is correct |
13 | Correct | 2 ms | 5016 KB | Output is correct |
14 | Correct | 2 ms | 4944 KB | Output is correct |
15 | Correct | 2 ms | 4948 KB | Output is correct |
16 | Correct | 3 ms | 5036 KB | Output is correct |
17 | Correct | 3 ms | 5012 KB | Output is correct |
18 | Correct | 2 ms | 5020 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 4948 KB | Output is correct |
2 | Correct | 4 ms | 4948 KB | Output is correct |
3 | Correct | 3 ms | 4948 KB | Output is correct |
4 | Correct | 2 ms | 4948 KB | Output is correct |
5 | Correct | 2 ms | 4948 KB | Output is correct |
6 | Correct | 2 ms | 4948 KB | Output is correct |
7 | Correct | 2 ms | 5012 KB | Output is correct |
8 | Correct | 2 ms | 4948 KB | Output is correct |
9 | Correct | 2 ms | 4948 KB | Output is correct |
10 | Correct | 2 ms | 4948 KB | Output is correct |
11 | Correct | 3 ms | 5016 KB | Output is correct |
12 | Correct | 2 ms | 5016 KB | Output is correct |
13 | Correct | 2 ms | 5016 KB | Output is correct |
14 | Correct | 2 ms | 4944 KB | Output is correct |
15 | Correct | 2 ms | 4948 KB | Output is correct |
16 | Correct | 3 ms | 5036 KB | Output is correct |
17 | Correct | 3 ms | 5012 KB | Output is correct |
18 | Correct | 2 ms | 5020 KB | Output is correct |
19 | Correct | 2 ms | 4948 KB | Output is correct |
20 | Correct | 3 ms | 4948 KB | Output is correct |
21 | Correct | 3 ms | 5076 KB | Output is correct |
22 | Correct | 4 ms | 8660 KB | Output is correct |
23 | Correct | 4 ms | 8020 KB | Output is correct |
24 | Correct | 6 ms | 8404 KB | Output is correct |
25 | Correct | 4 ms | 8404 KB | Output is correct |
26 | Correct | 3 ms | 6356 KB | Output is correct |
27 | Correct | 4 ms | 8228 KB | Output is correct |
28 | Correct | 3 ms | 5888 KB | Output is correct |
29 | Correct | 3 ms | 6356 KB | Output is correct |
30 | Correct | 4 ms | 6436 KB | Output is correct |
31 | Correct | 4 ms | 7636 KB | Output is correct |
32 | Correct | 4 ms | 7892 KB | Output is correct |
33 | Correct | 4 ms | 8096 KB | Output is correct |
34 | Correct | 4 ms | 7380 KB | Output is correct |
35 | Correct | 4 ms | 8276 KB | Output is correct |
36 | Correct | 4 ms | 8660 KB | Output is correct |
37 | Correct | 4 ms | 8148 KB | Output is correct |
38 | Correct | 3 ms | 7068 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 4948 KB | Output is correct |
2 | Correct | 4 ms | 4948 KB | Output is correct |
3 | Correct | 3 ms | 4948 KB | Output is correct |
4 | Correct | 2 ms | 4948 KB | Output is correct |
5 | Correct | 2 ms | 4948 KB | Output is correct |
6 | Correct | 2 ms | 4948 KB | Output is correct |
7 | Correct | 2 ms | 5012 KB | Output is correct |
8 | Correct | 2 ms | 4948 KB | Output is correct |
9 | Correct | 2 ms | 4948 KB | Output is correct |
10 | Correct | 2 ms | 4948 KB | Output is correct |
11 | Correct | 3 ms | 5016 KB | Output is correct |
12 | Correct | 2 ms | 5016 KB | Output is correct |
13 | Correct | 2 ms | 5016 KB | Output is correct |
14 | Correct | 2 ms | 4944 KB | Output is correct |
15 | Correct | 2 ms | 4948 KB | Output is correct |
16 | Correct | 3 ms | 5036 KB | Output is correct |
17 | Correct | 3 ms | 5012 KB | Output is correct |
18 | Correct | 2 ms | 5020 KB | Output is correct |
19 | Correct | 66 ms | 11808 KB | Output is correct |
20 | Correct | 75 ms | 11872 KB | Output is correct |
21 | Correct | 71 ms | 12140 KB | Output is correct |
22 | Correct | 66 ms | 12556 KB | Output is correct |
23 | Correct | 46 ms | 11980 KB | Output is correct |
24 | Correct | 35 ms | 11872 KB | Output is correct |
25 | Correct | 78 ms | 14512 KB | Output is correct |
26 | Correct | 63 ms | 18396 KB | Output is correct |
27 | Correct | 96 ms | 18776 KB | Output is correct |
28 | Correct | 152 ms | 30152 KB | Output is correct |
29 | Correct | 150 ms | 29144 KB | Output is correct |
30 | Correct | 96 ms | 18852 KB | Output is correct |
31 | Correct | 96 ms | 18760 KB | Output is correct |
32 | Correct | 117 ms | 18936 KB | Output is correct |
33 | Correct | 118 ms | 17560 KB | Output is correct |
34 | Correct | 107 ms | 18508 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 4948 KB | Output is correct |
2 | Correct | 4 ms | 4948 KB | Output is correct |
3 | Correct | 3 ms | 4948 KB | Output is correct |
4 | Correct | 2 ms | 4948 KB | Output is correct |
5 | Correct | 2 ms | 4948 KB | Output is correct |
6 | Correct | 2 ms | 4948 KB | Output is correct |
7 | Correct | 2 ms | 5012 KB | Output is correct |
8 | Correct | 2 ms | 4948 KB | Output is correct |
9 | Correct | 2 ms | 4948 KB | Output is correct |
10 | Correct | 2 ms | 4948 KB | Output is correct |
11 | Correct | 3 ms | 5016 KB | Output is correct |
12 | Correct | 2 ms | 5016 KB | Output is correct |
13 | Correct | 2 ms | 5016 KB | Output is correct |
14 | Correct | 2 ms | 4944 KB | Output is correct |
15 | Correct | 2 ms | 4948 KB | Output is correct |
16 | Correct | 3 ms | 5036 KB | Output is correct |
17 | Correct | 3 ms | 5012 KB | Output is correct |
18 | Correct | 2 ms | 5020 KB | Output is correct |
19 | Correct | 2 ms | 4948 KB | Output is correct |
20 | Correct | 3 ms | 4948 KB | Output is correct |
21 | Correct | 3 ms | 5076 KB | Output is correct |
22 | Correct | 4 ms | 8660 KB | Output is correct |
23 | Correct | 4 ms | 8020 KB | Output is correct |
24 | Correct | 6 ms | 8404 KB | Output is correct |
25 | Correct | 4 ms | 8404 KB | Output is correct |
26 | Correct | 3 ms | 6356 KB | Output is correct |
27 | Correct | 4 ms | 8228 KB | Output is correct |
28 | Correct | 3 ms | 5888 KB | Output is correct |
29 | Correct | 3 ms | 6356 KB | Output is correct |
30 | Correct | 4 ms | 6436 KB | Output is correct |
31 | Correct | 4 ms | 7636 KB | Output is correct |
32 | Correct | 4 ms | 7892 KB | Output is correct |
33 | Correct | 4 ms | 8096 KB | Output is correct |
34 | Correct | 4 ms | 7380 KB | Output is correct |
35 | Correct | 4 ms | 8276 KB | Output is correct |
36 | Correct | 4 ms | 8660 KB | Output is correct |
37 | Correct | 4 ms | 8148 KB | Output is correct |
38 | Correct | 3 ms | 7068 KB | Output is correct |
39 | Correct | 66 ms | 11808 KB | Output is correct |
40 | Correct | 75 ms | 11872 KB | Output is correct |
41 | Correct | 71 ms | 12140 KB | Output is correct |
42 | Correct | 66 ms | 12556 KB | Output is correct |
43 | Correct | 46 ms | 11980 KB | Output is correct |
44 | Correct | 35 ms | 11872 KB | Output is correct |
45 | Correct | 78 ms | 14512 KB | Output is correct |
46 | Correct | 63 ms | 18396 KB | Output is correct |
47 | Correct | 96 ms | 18776 KB | Output is correct |
48 | Correct | 152 ms | 30152 KB | Output is correct |
49 | Correct | 150 ms | 29144 KB | Output is correct |
50 | Correct | 96 ms | 18852 KB | Output is correct |
51 | Correct | 96 ms | 18760 KB | Output is correct |
52 | Correct | 117 ms | 18936 KB | Output is correct |
53 | Correct | 118 ms | 17560 KB | Output is correct |
54 | Correct | 107 ms | 18508 KB | Output is correct |
55 | Correct | 7 ms | 5716 KB | Output is correct |
56 | Correct | 9 ms | 5852 KB | Output is correct |
57 | Correct | 47 ms | 12740 KB | Output is correct |
58 | Correct | 28 ms | 12552 KB | Output is correct |
59 | Correct | 57 ms | 19100 KB | Output is correct |
60 | Correct | 221 ms | 35084 KB | Output is correct |
61 | Correct | 103 ms | 19176 KB | Output is correct |
62 | Correct | 117 ms | 23816 KB | Output is correct |
63 | Correct | 139 ms | 23720 KB | Output is correct |
64 | Correct | 211 ms | 22808 KB | Output is correct |
65 | Correct | 115 ms | 19608 KB | Output is correct |
66 | Correct | 213 ms | 31312 KB | Output is correct |
67 | Correct | 68 ms | 25220 KB | Output is correct |
68 | Correct | 142 ms | 23960 KB | Output is correct |
69 | Correct | 144 ms | 24144 KB | Output is correct |
70 | Correct | 128 ms | 23368 KB | Output is correct |