제출 #719113

#제출 시각아이디문제언어결과실행 시간메모리
719113irmuun구슬과 끈 (APIO14_beads)C++17
28 / 100
1074 ms1364 KiB
#include<bits/stdc++.h> using namespace std; #define pb push_back #define ll long long #define ff first #define ss second #define all(s) s.begin(),s.end() const ll N=10005; ll dp[2][N]; vector<pair<ll,ll>>adj[N]; void dfs(ll v,ll par){ for(auto [u,w]:adj[v]){ if(u!=par){ dp[1][u]=w; dfs(u,v); dp[0][v]=max(dp[0][v]+dp[0][u],dp[1][v]+dp[1][u]); dp[1][v]+=dp[0][u]; } } } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n; cin>>n; for(ll i=1;i<n;i++){ ll u,v,w; cin>>u>>v>>w; adj[u].pb({v,w}); adj[v].pb({u,w}); } ll ans=0; for(ll i=1;i<=n;i++){ fill(dp[0],dp[0]+n+1,0); fill(dp[1],dp[1]+n+1,0); dfs(i,-1); ans=max(ans,dp[1][i]); } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...