제출 #158442

#제출 시각아이디문제언어결과실행 시간메모리
158442arnold518Beads and wires (APIO14_beads)C++14
0 / 100
6 ms5028 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) { vector<ll> V; ll S=0; for(pii nxt : adj[now]) { if(nxt.first==bef) continue; dfs(nxt.first, now, nxt.second); S+=max(dp1[nxt.first], dp2[nxt.first]); V.push_back(dp2[nxt.first]+nxt.second-max(dp1[nxt.first], dp2[nxt.first])); } sort(V.begin(), V.end(), greater<ll>()); dp2[now]=S; if(V.size()>1 && V[0]+V[1]>=0) dp2[now]+=V[0]+V[1]; if(V.size()<=0) dp1[now]=-1e15; else dp1[now]=S+par+V[0]; //printf("%d %lld %lld\n", now, dp1[now], dp2[now]); } 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}); } dfs(1, 1, 0); printf("%lld", dp2[1]); }

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

beads.cpp: In function 'int main()':
beads.cpp:38:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
beads.cpp:40:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
beads.cpp:44: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...