제출 #206269

#제출 시각아이디문제언어결과실행 시간메모리
206269achibasadzishvili구슬과 끈 (APIO14_beads)C++17
0 / 100
12 ms12024 KiB
#include<bits/stdc++.h> #define ll long long #define f first #define s second #define pb push_back #define mp make_pair using namespace std; ll n,dp[2][500005]; vector<pair<ll,ll> >v[500005]; void solve(ll x,ll par,ll dis){ ll mx1 = -99999999999 , mx2 = -99999999999 , sum = 0; for(int i=0; i<v[x].size(); i++) if(v[x][i].f != par){ ll to = v[x][i].f; solve(to , x , v[x][i].s); sum += max(dp[0][to] , dp[1][to]); ll cur = dp[0][to] + v[x][i].s - max(dp[0][to] , dp[1][to]); if(cur > mx1)mx2 = mx1 , mx1 = cur; else if(cur > mx2)mx2 = cur; } if(v[x].size() - 1 + (x == 1) > 1)dp[0][x] = max(sum , sum + mx1 + mx2); if(x != 1 && v[x].size() > 1) dp[1][x] = sum + mx1 + dis; //cout << x << " " << dp[0][x] << " " << dp[1][x] << '\n'; } int main(){ ios::sync_with_stdio(false); cin >> n; for(int i=1; i<n; i++){ ll x,y,z; cin >> x >> y >> z; v[x].pb(mp(y , z)); v[y].pb(mp(x , z)); } solve(1 , 0 , 0); cout << max(dp[0][1] , dp[1][1]) << '\n'; return 0; }

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

beads.cpp: In function 'void solve(long long int, long long int, long long int)':
beads.cpp:12:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<v[x].size(); i++)
                  ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...