# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
580928 | 2022-06-22T06:28:54 Z | 조영욱(#8362) | Beads and wires (APIO14_beads) | C++17 | 1000 ms | 9940 KB |
#include <bits/stdc++.h> using namespace std; int n; typedef pair<int,int> P; vector<P> adj[200001]; long long dp[200001][2]; vector<P> son[200001]; const long long nnn=-1e16; const long long nn=-1e12-7; int rr; void dfs(int v,int prev) { dp[v][0]=nnn; dp[v][1]=nnn; vector<P> son; for(int i=0;i<adj[v].size();i++) { P nt=adj[v][i]; if (nt.first!=prev) { son.push_back(nt); dfs(nt.first,v); } } if (1) { long long ret=0; long long mx=0; for(int i=0;i<son.size();i++) { ret+=max(dp[son[i].first][0],dp[son[i].first][1]+son[i].second); } dp[v][0]=ret+mx; } if (1) { long long ret=0; long long mx=nn; for(int i=0;i<son.size();i++) { ret+=max(dp[son[i].first][0],dp[son[i].first][1]+son[i].second); mx=max(mx,dp[son[i].first][0]+son[i].second-max(dp[son[i].first][0],dp[son[i].first][1]+son[i].second)); } dp[v][1]=ret+mx; } } int main(void) { scanf("%d",&n); for(int i=1;i<n;i++) { int u,v,w; scanf("%d %d %d",&u,&v,&w); u--; v--; adj[u].push_back(P(v,w)); adj[v].push_back(P(u,w)); } long long ret=0; for(int r=0;r<n;r++) { rr=r; dfs(r,-1); ret=max(ret,dp[r][0]); } printf("%lld",ret); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 9684 KB | Output is correct |
2 | Correct | 7 ms | 9696 KB | Output is correct |
3 | Correct | 6 ms | 9684 KB | Output is correct |
4 | Correct | 7 ms | 9684 KB | Output is correct |
5 | Correct | 6 ms | 9684 KB | Output is correct |
6 | Correct | 5 ms | 9684 KB | Output is correct |
7 | Correct | 6 ms | 9664 KB | Output is correct |
8 | Correct | 6 ms | 9708 KB | Output is correct |
9 | Correct | 5 ms | 9704 KB | Output is correct |
10 | Correct | 5 ms | 9684 KB | Output is correct |
11 | Correct | 6 ms | 9712 KB | Output is correct |
12 | Correct | 6 ms | 9684 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 9684 KB | Output is correct |
2 | Correct | 7 ms | 9696 KB | Output is correct |
3 | Correct | 6 ms | 9684 KB | Output is correct |
4 | Correct | 7 ms | 9684 KB | Output is correct |
5 | Correct | 6 ms | 9684 KB | Output is correct |
6 | Correct | 5 ms | 9684 KB | Output is correct |
7 | Correct | 6 ms | 9664 KB | Output is correct |
8 | Correct | 6 ms | 9708 KB | Output is correct |
9 | Correct | 5 ms | 9704 KB | Output is correct |
10 | Correct | 5 ms | 9684 KB | Output is correct |
11 | Correct | 6 ms | 9712 KB | Output is correct |
12 | Correct | 6 ms | 9684 KB | Output is correct |
13 | Correct | 6 ms | 9708 KB | Output is correct |
14 | Correct | 6 ms | 9684 KB | Output is correct |
15 | Correct | 6 ms | 9708 KB | Output is correct |
16 | Correct | 8 ms | 9684 KB | Output is correct |
17 | Correct | 7 ms | 9684 KB | Output is correct |
18 | Correct | 7 ms | 9684 KB | Output is correct |
19 | Correct | 7 ms | 9684 KB | Output is correct |
20 | Correct | 6 ms | 9704 KB | Output is correct |
21 | Correct | 6 ms | 9608 KB | Output is correct |
22 | Correct | 7 ms | 9684 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 9684 KB | Output is correct |
2 | Correct | 7 ms | 9696 KB | Output is correct |
3 | Correct | 6 ms | 9684 KB | Output is correct |
4 | Correct | 7 ms | 9684 KB | Output is correct |
5 | Correct | 6 ms | 9684 KB | Output is correct |
6 | Correct | 5 ms | 9684 KB | Output is correct |
7 | Correct | 6 ms | 9664 KB | Output is correct |
8 | Correct | 6 ms | 9708 KB | Output is correct |
9 | Correct | 5 ms | 9704 KB | Output is correct |
10 | Correct | 5 ms | 9684 KB | Output is correct |
11 | Correct | 6 ms | 9712 KB | Output is correct |
12 | Correct | 6 ms | 9684 KB | Output is correct |
13 | Correct | 6 ms | 9708 KB | Output is correct |
14 | Correct | 6 ms | 9684 KB | Output is correct |
15 | Correct | 6 ms | 9708 KB | Output is correct |
16 | Correct | 8 ms | 9684 KB | Output is correct |
17 | Correct | 7 ms | 9684 KB | Output is correct |
18 | Correct | 7 ms | 9684 KB | Output is correct |
19 | Correct | 7 ms | 9684 KB | Output is correct |
20 | Correct | 6 ms | 9704 KB | Output is correct |
21 | Correct | 6 ms | 9608 KB | Output is correct |
22 | Correct | 7 ms | 9684 KB | Output is correct |
23 | Execution timed out | 1089 ms | 9940 KB | Time limit exceeded |
24 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 9684 KB | Output is correct |
2 | Correct | 7 ms | 9696 KB | Output is correct |
3 | Correct | 6 ms | 9684 KB | Output is correct |
4 | Correct | 7 ms | 9684 KB | Output is correct |
5 | Correct | 6 ms | 9684 KB | Output is correct |
6 | Correct | 5 ms | 9684 KB | Output is correct |
7 | Correct | 6 ms | 9664 KB | Output is correct |
8 | Correct | 6 ms | 9708 KB | Output is correct |
9 | Correct | 5 ms | 9704 KB | Output is correct |
10 | Correct | 5 ms | 9684 KB | Output is correct |
11 | Correct | 6 ms | 9712 KB | Output is correct |
12 | Correct | 6 ms | 9684 KB | Output is correct |
13 | Correct | 6 ms | 9708 KB | Output is correct |
14 | Correct | 6 ms | 9684 KB | Output is correct |
15 | Correct | 6 ms | 9708 KB | Output is correct |
16 | Correct | 8 ms | 9684 KB | Output is correct |
17 | Correct | 7 ms | 9684 KB | Output is correct |
18 | Correct | 7 ms | 9684 KB | Output is correct |
19 | Correct | 7 ms | 9684 KB | Output is correct |
20 | Correct | 6 ms | 9704 KB | Output is correct |
21 | Correct | 6 ms | 9608 KB | Output is correct |
22 | Correct | 7 ms | 9684 KB | Output is correct |
23 | Execution timed out | 1089 ms | 9940 KB | Time limit exceeded |
24 | Halted | 0 ms | 0 KB | - |