Submission #580914

# Submission time Handle Problem Language Result Execution time Memory
580914 2022-06-22T06:02:34 Z 반딧불(#8360) Beads and wires (APIO14_beads) C++17
28 / 100
1000 ms 5716 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n;
vector<pair<int, ll> > link[200002];
ll ans;

ll DP[10002][2]; /// DP[i][0]: i�� �� �������� ���� ����, DP[i][1]: i�� �� ������ ����

void dfs(int x, int p=-1){
    ll maxAdd = -1e12;
    for(auto py: link[x]){
        int y = py.first;
        if(y == p) continue;
        dfs(y, x);
        DP[x][0] += max(DP[y][0], DP[y][1] + py.second);
        maxAdd = max(maxAdd, DP[y][0] + py.second - max(DP[y][0], DP[y][1] + py.second));
    }
    DP[x][1] = DP[x][0] + maxAdd;
}

ll solve(int root){
    for(int i=1; i<=n; i++) DP[i][0] = 0, DP[i][1] = -1e12;
    dfs(root);
    return DP[root][0];
}

int main(){
    scanf("%d", &n);
    for(int i=1; i<n; i++){
        int x, y, z;
        scanf("%d %d %d", &x, &y, &z);
        link[x].push_back(make_pair(y, z));
        link[y].push_back(make_pair(x, z));
    }
    for(int i=1; i<=n; i++){
        ans = max(ans, solve(i));
    }
    printf("%lld", ans);
}

Compilation message

beads.cpp: In function 'int main()':
beads.cpp:32:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
beads.cpp:35:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |         scanf("%d %d %d", &x, &y, &z);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 5000 KB Output is correct
8 Correct 3 ms 4892 KB Output is correct
9 Correct 3 ms 5076 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 5000 KB Output is correct
8 Correct 3 ms 4892 KB Output is correct
9 Correct 3 ms 5076 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 4 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 5000 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 5004 KB Output is correct
20 Correct 3 ms 5000 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 5 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 5000 KB Output is correct
8 Correct 3 ms 4892 KB Output is correct
9 Correct 3 ms 5076 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 4 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 5000 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 5004 KB Output is correct
20 Correct 3 ms 5000 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 5 ms 4948 KB Output is correct
23 Correct 585 ms 5384 KB Output is correct
24 Correct 552 ms 5380 KB Output is correct
25 Correct 604 ms 5384 KB Output is correct
26 Execution timed out 1089 ms 5716 KB Time limit exceeded
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 2 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 5000 KB Output is correct
8 Correct 3 ms 4892 KB Output is correct
9 Correct 3 ms 5076 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 4 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 5000 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 3 ms 5004 KB Output is correct
20 Correct 3 ms 5000 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 5 ms 4948 KB Output is correct
23 Correct 585 ms 5384 KB Output is correct
24 Correct 552 ms 5380 KB Output is correct
25 Correct 604 ms 5384 KB Output is correct
26 Execution timed out 1089 ms 5716 KB Time limit exceeded
27 Halted 0 ms 0 KB -