# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
100232 | TadijaSebez | 구슬과 끈 (APIO14_beads) | C++11 | 7 ms | 4992 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
const int N=200050;
const ll inf=1e18;
ll dp[N][2];
vector<pair<int,int>> E[N];
void Solve(int u, int p, int w)
{
ll sum=0,fir=-inf,sec=-inf;
for(auto e:E[u]) if(e.first!=p)
{
Solve(e.first,u,e.second);
sum+=max(dp[e.first][0],dp[e.first][1]);
ll dif=dp[e.first][0]-max(dp[e.first][0],dp[e.first][1])+e.second;
if(fir<=dif) sec=fir,fir=dif;
else sec=max(sec,dif);
}
dp[u][1]=sum+fir+w;
dp[u][0]=max(sum,sum+fir+sec);
}
int main()
{
int n,i,u,v,w;
scanf("%i",&n);
for(i=1;i<n;i++) scanf("%i %i %i",&u,&v,&w),E[u].pb(mp(v,w)),E[v].pb(mp(u,w));
Solve(1,0,0);
printf("%lld\n",dp[1][0]);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |