제출 #33966

#제출 시각아이디문제언어결과실행 시간메모리
33966mohammad_kilani구슬과 끈 (APIO14_beads)C++14
0 / 100
10 ms9728 KiB
#include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define oo 2000000000 const int N = 300010; int n , dp[N][2]; vector< pair<int,int> > g[N]; int solve(int node,int prnt,int len,bool b){ if(dp[node][b] != -1) return dp[node][b]; int sum = 0 ; dp[node][b] = 0 ; vector<int> v; for(int i=0;i<g[node].size();i++){ if(g[node][i].first != prnt){ int cur = solve(g[node][i].first,node,g[node][i].second,0); int cur2 = solve(g[node][i].first,node,g[node][i].second,1); sum += cur2; v.push_back(cur - cur2 + g[node][i].second); } } dp[node][b] = sum; sort(v.begin(),v.end()); if(v.size() > 1) dp[node][b] = max(dp[node][b],v[v.size()-1] + v[v.size()-2] + sum); if(b && v.size() > 0) dp[node][b] = max(dp[node][b],sum + len + v.back()); return dp[node][b]; } int main() { //freopen("in.txt","r",stdin); scanf("%d",&n); for(int i=0;i<n-1;i++){ int u , v, w; scanf("%d%d%d",&u,&v,&w); g[u].push_back(make_pair(v,w)); g[v].push_back(make_pair(u,w)); } memset(dp,-1,sizeof(dp)); cout<< solve(1,-1,0,0) << endl; return 0; }

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

beads.cpp: In function 'int solve(int, int, int, bool)':
beads.cpp:14:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<g[node].size();i++){
              ~^~~~~~~~~~~~~~~
beads.cpp: In function 'int main()':
beads.cpp:31:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
beads.cpp:34:8: 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...