Submission #122303

# Submission time Handle Problem Language Result Execution time Memory
122303 2019-06-28T04:32:28 Z 송준혁(#2992) Beads and wires (APIO14_beads) C++14
0 / 100
6 ms 5120 KB
#include <bits/stdc++.h>
#define INF (1ll<<60)
using namespace std;
typedef long long LL;
typedef pair<int, LL> pii;

int N;
LL D1[202020], D2[202020];
vector<pii> adj[202020];

void dfs(int u, int p, LL w){
    LL Max1 = -INF, Max2 = -INF;
    for (pii v : adj[u]){
        if (v.first == p) continue;
        dfs(v.first, u, v.second);
        D2[u] += D1[v.first];
        LL t = D2[v.first] - D1[v.first] + v.second;
        if (Max1 <= t) Max2 = Max1, Max1 = t;
        else if (Max2 < t) Max2 = t;
    }
    D1[u] = D2[u] + Max1 + w;
    D2[u] = max(D2[u], D2[u] + Max1 + Max2);
    D1[u] = max(D1[u], D2[u]);
}

int main(){
    int u, v, w;
    scanf("%d", &N);
    for (int i=1; i<N; i++){
        scanf("%d %d %d", &u, &v, &w);
        adj[u].push_back(pii(v, w));
        adj[v].push_back(pii(u, w));
    }
    dfs(1, 0, -INF);
    printf("%lld\n", D1[1]);
    return 0;
}

Compilation message

beads.cpp: In function 'int main()':
beads.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
beads.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d", &u, &v, &w);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5092 KB Output is correct
2 Correct 6 ms 5020 KB Output is correct
3 Correct 6 ms 5120 KB Output is correct
4 Correct 6 ms 5120 KB Output is correct
5 Correct 5 ms 5120 KB Output is correct
6 Incorrect 5 ms 5120 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5092 KB Output is correct
2 Correct 6 ms 5020 KB Output is correct
3 Correct 6 ms 5120 KB Output is correct
4 Correct 6 ms 5120 KB Output is correct
5 Correct 5 ms 5120 KB Output is correct
6 Incorrect 5 ms 5120 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5092 KB Output is correct
2 Correct 6 ms 5020 KB Output is correct
3 Correct 6 ms 5120 KB Output is correct
4 Correct 6 ms 5120 KB Output is correct
5 Correct 5 ms 5120 KB Output is correct
6 Incorrect 5 ms 5120 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5092 KB Output is correct
2 Correct 6 ms 5020 KB Output is correct
3 Correct 6 ms 5120 KB Output is correct
4 Correct 6 ms 5120 KB Output is correct
5 Correct 5 ms 5120 KB Output is correct
6 Incorrect 5 ms 5120 KB Output isn't correct
7 Halted 0 ms 0 KB -