제출 #140312

#제출 시각아이디문제언어결과실행 시간메모리
140312FedericoS구슬과 끈 (APIO14_beads)C++14
0 / 100
6 ms4984 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; typedef pair<int,int> pii; int N; int x,y,z; vector<pii> grafo[200005]; int A[200005],B[200005]; void DFS(int k, int p=-1){ for(pii f:grafo[k]) if(f.first!=p) DFS(f.first,k); vector<int> v; for(pii f:grafo[k]) if(f.first!=p){ A[k]+=max(A[f.first],B[f.first]+f.second); v.push_back(A[f.first]+f.second-max(A[f.first],B[f.first]+f.second)); } sort(v.begin(),v.end(),greater<int>()); if(grafo[k].size()==1 and k!=1) B[k]=-2e9; else B[k]=A[k]+v[0]; if(v.size()>1 and v[0]+v[1]>0) A[k]=A[k]+v[0]+v[1]; } int main(){ cin>>N; for(int i=0;i<N-1;i++){ cin>>x>>y>>z; grafo[x].push_back({y,z}); grafo[y].push_back({x,z}); } DFS(1); cout<<A[1]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...