# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
349196 | 2021-01-17T03:51:21 Z | arnold518 | Museum (CEOI17_museum) | C++14 | 475 ms | 360348 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 1e4; const ll INF = 1e18; int N, K, R; vector<pii> adj[MAXN+10]; int sz[MAXN+10]; ll dp1[MAXN+10][MAXN+10], dp2[MAXN+10][MAXN+10]; ll T1[MAXN+10], T2[MAXN+10]; void dfs(int now, int bef) { //printf("%d %d\n", now, bef); sz[now]=1; dp1[now][0]=INF; dp1[now][1]=0; dp2[now][0]=INF; dp2[now][1]=0; for(auto nxt : adj[now]) { if(nxt.first==bef) continue; dfs(nxt.first, now); for(int i=0; i<=sz[now]+sz[nxt.first]; i++) T1[i]=T2[i]=INF; for(int i=0; i<=sz[now]; i++) { for(int j=0; j<=sz[nxt.first]; j++) { if(j) { T1[i+j]=min(T1[i+j], dp1[now][i]+dp2[nxt.first][j]+nxt.second*2); T1[i+j]=min(T1[i+j], dp2[now][i]+dp1[nxt.first][j]+nxt.second); T2[i+j]=min(T2[i+j], dp2[now][i]+dp2[nxt.first][j]+nxt.second*2); } else { T1[i+j]=min(T1[i+j], dp1[now][i]); T2[i+j]=min(T2[i+j], dp2[now][i]); } } } for(int i=0; i<=sz[now]+sz[nxt.first]; i++) { dp1[now][i]=T1[i]; dp2[now][i]=T2[i]; } sz[now]+=sz[nxt.first]; } } int main() { scanf("%d%d%d", &N, &K, &R); for(int i=1; i<N; i++) { int u, v, w; scanf("%d%d%d", &u, &v, &w); adj[u].push_back({v, w}); adj[v].push_back({u, w}); } dfs(R, R); printf("%lld\n", dp1[R][K]); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 748 KB | Output is correct |
2 | Correct | 1 ms | 748 KB | Output is correct |
3 | Correct | 1 ms | 748 KB | Output is correct |
4 | Correct | 1 ms | 748 KB | Output is correct |
5 | Correct | 1 ms | 620 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 215 ms | 87660 KB | Output is correct |
2 | Correct | 217 ms | 88300 KB | Output is correct |
3 | Correct | 463 ms | 352668 KB | Output is correct |
4 | Correct | 300 ms | 169220 KB | Output is correct |
5 | Correct | 230 ms | 105452 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 215 ms | 87660 KB | Output is correct |
2 | Correct | 217 ms | 88300 KB | Output is correct |
3 | Correct | 463 ms | 352668 KB | Output is correct |
4 | Correct | 300 ms | 169220 KB | Output is correct |
5 | Correct | 230 ms | 105452 KB | Output is correct |
6 | Correct | 214 ms | 86380 KB | Output is correct |
7 | Correct | 370 ms | 241132 KB | Output is correct |
8 | Correct | 471 ms | 84844 KB | Output is correct |
9 | Correct | 379 ms | 84972 KB | Output is correct |
10 | Correct | 242 ms | 86124 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 748 KB | Output is correct |
2 | Correct | 1 ms | 748 KB | Output is correct |
3 | Correct | 1 ms | 748 KB | Output is correct |
4 | Correct | 1 ms | 748 KB | Output is correct |
5 | Correct | 1 ms | 620 KB | Output is correct |
6 | Correct | 215 ms | 87660 KB | Output is correct |
7 | Correct | 217 ms | 88300 KB | Output is correct |
8 | Correct | 463 ms | 352668 KB | Output is correct |
9 | Correct | 300 ms | 169220 KB | Output is correct |
10 | Correct | 230 ms | 105452 KB | Output is correct |
11 | Correct | 214 ms | 86380 KB | Output is correct |
12 | Correct | 370 ms | 241132 KB | Output is correct |
13 | Correct | 471 ms | 84844 KB | Output is correct |
14 | Correct | 379 ms | 84972 KB | Output is correct |
15 | Correct | 242 ms | 86124 KB | Output is correct |
16 | Correct | 215 ms | 89068 KB | Output is correct |
17 | Correct | 214 ms | 88444 KB | Output is correct |
18 | Correct | 318 ms | 189036 KB | Output is correct |
19 | Correct | 406 ms | 84844 KB | Output is correct |
20 | Correct | 223 ms | 86508 KB | Output is correct |
21 | Correct | 358 ms | 234988 KB | Output is correct |
22 | Correct | 215 ms | 88172 KB | Output is correct |
23 | Correct | 401 ms | 84844 KB | Output is correct |
24 | Correct | 219 ms | 86124 KB | Output is correct |
25 | Correct | 475 ms | 360348 KB | Output is correct |