제출 #216394

#제출 시각아이디문제언어결과실행 시간메모리
216394DodgeBallMan구슬과 끈 (APIO14_beads)C++14
0 / 100
7 ms4992 KiB
#include <bits/stdc++.h> #define pii pair<int, int> #define x first #define y second using namespace std; const int N = 2e5 + 10; int dp[N][2], va[N], n; vector<pii> g[N]; void pre( int u, int p, int vv ) { va[u] = vv; for( pii v : g[u] ) if( v.x != p ) { pre( v.x, u, v.y ); } } void dfs( int u, int p ) { //printf("%d %d\n",u,p); vector<int> vec; int cnt = g[u].size(); if( u != 1 ) cnt--; if( !cnt ) return void( dp[u][1] = -1e9 ); if( cnt == 1 ) { for( pii x : g[u] ) if( x.x != p ) { int v = x.x; dfs( v, u ); dp[u][0] = max( dp[v][0], va[v] + dp[v][1] ); dp[u][1] = dp[v][0] + va[v]; } return ; } for( pii x : g[u] ) if( x.x != p ) { int v = x.x; dfs( v, u ); //printf("NODE U P V : %d %d %d %d %d\n",u,p,v,dp[v][0],dp[v][1]); int mx = max( dp[v][0], dp[v][1] + va[v] ); dp[u][0] += mx, dp[u][1] += mx; //printf("%d\n",mx); vec.emplace_back( va[v] + dp[v][0] - mx ); } sort( vec.begin(), vec.end(), greater<int>() ); /*for( int i : vec ) printf("%d ",i); printf("\n");*/ if( vec[0] + vec[1] > 0 ) dp[u][0] += vec[0] + vec[1]; dp[u][1] += vec[0]; //printf("%d %d %d\n",u,dp[u][0],dp[u][1]); return ; } int main() { scanf("%d",&n); for( int i = 1, a, b, c ; i < n ; i++ ) { scanf("%d %d %d",&a,&b,&c); g[a].emplace_back( b, c ), g[b].emplace_back( a, c ); } pre( 1, 0, 0 ), dfs( 1, 0 ); printf("%d",dp[1][0]); return 0; }

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

beads.cpp: In function 'int main()':
beads.cpp:52:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
beads.cpp:54:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d",&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...