제출 #158433

#제출 시각아이디문제언어결과실행 시간메모리
158433mhy908구슬과 끈 (APIO14_beads)C++14
0 / 100
7 ms4984 KiB
#include <bits/stdc++.h> #define F first #define S second #define pb push_back #define mp make_pair #define inf 1987654321 using namespace std; typedef long long LL; int n; LL dp1[200010], dp2[200010], dp[200010]; vector<pair<int, LL> > link[200010]; void get_dp(int num, int par, LL c) { LL sum=0; vector<LL> comp; for(int i=0; i<link[num].size(); i++){ if(par==link[num][i].F)continue; get_dp(link[num][i].F, num, link[num][i].S); sum+=dp[link[num][i].F]; comp.pb(-dp[link[num][i].F]+dp2[link[num][i].F]+link[num][i].S); } sort(comp.begin(), comp.end(), greater<LL>()); if(comp.size()>=1)dp1[num]=sum+comp[0]+c; if(comp.size()>=2)dp2[num]=sum+comp[0]+comp[1]; dp[num]=max(dp1[num], dp2[num]); } int main() { scanf("%d", &n); for(int i=1; i<n; i++){ int a, b; LL c; scanf("%d %d %lld", &a, &b, &c); link[a].pb(mp(b, c)); link[b].pb(mp(a, c)); } get_dp(1, 0, -inf); printf("%lld", dp[1]); }

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

beads.cpp: In function 'void get_dp(int, int, LL)':
beads.cpp:16:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<link[num].size(); i++){
                  ~^~~~~~~~~~~~~~~~~
beads.cpp: In function 'int main()':
beads.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
beads.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %lld", &a, &b, &c);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...