제출 #1110963

#제출 시각아이디문제언어결과실행 시간메모리
1110963simona1230구슬과 끈 (APIO14_beads)C++17
28 / 100
1041 ms1104 KiB
#include <bits/stdc++.h> using namespace std; int n; vector<pair<int,int> > v[10001]; void read() { cin>>n; for(int i=1;i<n;i++) { int x,y,z; cin>>x>>y>>z; v[x].push_back({y,z}); v[y].push_back({x,z}); } } int dp[10001][2]; int used[100001],b; void dfs(int i) { used[i]=b; dp[i][0]=0; int minn=1e9,h=0; for(int j=0;j<v[i].size();j++) { if(used[v[i][j].first]==b)continue; dfs(v[i][j].first); if(dp[v[i][j].first][0]<dp[v[i][j].first][1]+v[i][j].second)h=dp[v[i][j].first][1]+v[i][j].second; else h=dp[v[i][j].first][0]; dp[i][0]+=h; minn=min(minn,h-dp[v[i][j].first][0]-v[i][j].second); } dp[i][1]=dp[i][0]-minn; if(v[i].size()==1)dp[i][1]=-1e9; //cout<<i<<" "<<dp[i][0]<<" "<<dp[i][1]<<endl; } void solve() { int ans=0; for(int i=1;i<=n;i++) { b=i; //cout<<"! "<<i<<endl; dfs(i); ans=max(ans,dp[i][0]); } cout<<ans<<'\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); read(); solve(); return 0; } /* 10 4 10 2 1 2 21 1 3 13 6 7 1 7 9 5 2 4 3 2 5 8 1 6 55 6 8 34 */

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

beads.cpp: In function 'void dfs(int)':
beads.cpp:26:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for(int j=0;j<v[i].size();j++)
      |                 ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...