# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
125113 | 2019-07-04T15:59:21 Z | TadijaSebez | Beads and wires (APIO14_beads) | C++11 | 1000 ms | 3192 KB |
#include <bits/stdc++.h> using namespace std; #define pb push_back const int N=100050; const int inf=1e9+7; vector<pair<int,int>> E[N]; int dp[N][2]; void DFS(int u, int p, int w) { dp[u][0]=0; int mx=-inf; for(auto e:E[u]) if(e.first!=p) { int v=e.first; DFS(v,u,e.second); dp[u][0]+=max(dp[v][0],dp[v][1]); mx=max(mx,dp[v][0]+w+e.second-max(dp[v][0],dp[v][1])); } dp[u][1]=dp[u][0]+mx; } int main() { int n,u,v,w; scanf("%i",&n); for(int i=1;i<n;i++) scanf("%i %i %i",&u,&v,&w),E[u].pb({v,w}),E[v].pb({u,w}); int ans=-inf; for(int i=1;i<=n;i++) DFS(i,0,0),ans=max(ans,dp[i][0]); printf("%i\n",ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2680 KB | Output is correct |
2 | Correct | 5 ms | 2712 KB | Output is correct |
3 | Correct | 4 ms | 2680 KB | Output is correct |
4 | Correct | 4 ms | 2680 KB | Output is correct |
5 | Correct | 4 ms | 2680 KB | Output is correct |
6 | Correct | 4 ms | 2680 KB | Output is correct |
7 | Correct | 4 ms | 2680 KB | Output is correct |
8 | Correct | 4 ms | 2680 KB | Output is correct |
9 | Correct | 4 ms | 2680 KB | Output is correct |
10 | Correct | 4 ms | 2708 KB | Output is correct |
11 | Correct | 4 ms | 2680 KB | Output is correct |
12 | Correct | 4 ms | 2680 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2680 KB | Output is correct |
2 | Correct | 5 ms | 2712 KB | Output is correct |
3 | Correct | 4 ms | 2680 KB | Output is correct |
4 | Correct | 4 ms | 2680 KB | Output is correct |
5 | Correct | 4 ms | 2680 KB | Output is correct |
6 | Correct | 4 ms | 2680 KB | Output is correct |
7 | Correct | 4 ms | 2680 KB | Output is correct |
8 | Correct | 4 ms | 2680 KB | Output is correct |
9 | Correct | 4 ms | 2680 KB | Output is correct |
10 | Correct | 4 ms | 2708 KB | Output is correct |
11 | Correct | 4 ms | 2680 KB | Output is correct |
12 | Correct | 4 ms | 2680 KB | Output is correct |
13 | Correct | 4 ms | 2684 KB | Output is correct |
14 | Correct | 4 ms | 2680 KB | Output is correct |
15 | Correct | 4 ms | 2680 KB | Output is correct |
16 | Correct | 5 ms | 2680 KB | Output is correct |
17 | Correct | 5 ms | 2680 KB | Output is correct |
18 | Correct | 5 ms | 2684 KB | Output is correct |
19 | Correct | 4 ms | 2684 KB | Output is correct |
20 | Correct | 5 ms | 2680 KB | Output is correct |
21 | Correct | 4 ms | 2680 KB | Output is correct |
22 | Correct | 5 ms | 2684 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2680 KB | Output is correct |
2 | Correct | 5 ms | 2712 KB | Output is correct |
3 | Correct | 4 ms | 2680 KB | Output is correct |
4 | Correct | 4 ms | 2680 KB | Output is correct |
5 | Correct | 4 ms | 2680 KB | Output is correct |
6 | Correct | 4 ms | 2680 KB | Output is correct |
7 | Correct | 4 ms | 2680 KB | Output is correct |
8 | Correct | 4 ms | 2680 KB | Output is correct |
9 | Correct | 4 ms | 2680 KB | Output is correct |
10 | Correct | 4 ms | 2708 KB | Output is correct |
11 | Correct | 4 ms | 2680 KB | Output is correct |
12 | Correct | 4 ms | 2680 KB | Output is correct |
13 | Correct | 4 ms | 2684 KB | Output is correct |
14 | Correct | 4 ms | 2680 KB | Output is correct |
15 | Correct | 4 ms | 2680 KB | Output is correct |
16 | Correct | 5 ms | 2680 KB | Output is correct |
17 | Correct | 5 ms | 2680 KB | Output is correct |
18 | Correct | 5 ms | 2684 KB | Output is correct |
19 | Correct | 4 ms | 2684 KB | Output is correct |
20 | Correct | 5 ms | 2680 KB | Output is correct |
21 | Correct | 4 ms | 2680 KB | Output is correct |
22 | Correct | 5 ms | 2684 KB | Output is correct |
23 | Correct | 822 ms | 3040 KB | Output is correct |
24 | Correct | 818 ms | 3000 KB | Output is correct |
25 | Correct | 806 ms | 2936 KB | Output is correct |
26 | Execution timed out | 1080 ms | 3192 KB | Time limit exceeded |
27 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2680 KB | Output is correct |
2 | Correct | 5 ms | 2712 KB | Output is correct |
3 | Correct | 4 ms | 2680 KB | Output is correct |
4 | Correct | 4 ms | 2680 KB | Output is correct |
5 | Correct | 4 ms | 2680 KB | Output is correct |
6 | Correct | 4 ms | 2680 KB | Output is correct |
7 | Correct | 4 ms | 2680 KB | Output is correct |
8 | Correct | 4 ms | 2680 KB | Output is correct |
9 | Correct | 4 ms | 2680 KB | Output is correct |
10 | Correct | 4 ms | 2708 KB | Output is correct |
11 | Correct | 4 ms | 2680 KB | Output is correct |
12 | Correct | 4 ms | 2680 KB | Output is correct |
13 | Correct | 4 ms | 2684 KB | Output is correct |
14 | Correct | 4 ms | 2680 KB | Output is correct |
15 | Correct | 4 ms | 2680 KB | Output is correct |
16 | Correct | 5 ms | 2680 KB | Output is correct |
17 | Correct | 5 ms | 2680 KB | Output is correct |
18 | Correct | 5 ms | 2684 KB | Output is correct |
19 | Correct | 4 ms | 2684 KB | Output is correct |
20 | Correct | 5 ms | 2680 KB | Output is correct |
21 | Correct | 4 ms | 2680 KB | Output is correct |
22 | Correct | 5 ms | 2684 KB | Output is correct |
23 | Correct | 822 ms | 3040 KB | Output is correct |
24 | Correct | 818 ms | 3000 KB | Output is correct |
25 | Correct | 806 ms | 2936 KB | Output is correct |
26 | Execution timed out | 1080 ms | 3192 KB | Time limit exceeded |
27 | Halted | 0 ms | 0 KB | - |