제출 #161551

#제출 시각아이디문제언어결과실행 시간메모리
161551arnold518구슬과 끈 (APIO14_beads)C++14
28 / 100
1076 ms8452 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 2e5;

int N;
vector<pii> adj[MAXN+10];
ll dp1[MAXN+10], dp2[MAXN+10];

void dfs(int now, int bef, int par)
{
    ll val=0;
    for(pii nxt : adj[now])
    {
        if(nxt.first==bef) continue;
        dfs(nxt.first, now, nxt.second);
        dp2[now]+=dp1[nxt.first];
        val=max(val, par-dp1[nxt.first]+dp2[nxt.first]+nxt.second);
    }
    dp1[now]=dp2[now]+val;
}

int main()
{
    int i, j;

    scanf("%d", &N);
    for(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});
    }

    ll ans=0;
    for(i=1; i<=N; i++)
    {
        memset(dp1, 0, sizeof(dp1));
        memset(dp2, 0, sizeof(dp2));
        dfs(i, i, 0);
        ans=max(ans, dp2[i]);
    }
    printf("%lld", ans);
}

컴파일 시 표준 에러 (stderr) 메시지

beads.cpp: In function 'int main()':
beads.cpp:29:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
beads.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
beads.cpp:35: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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...