| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 100235 | TadijaSebez | 구슬과 끈 (APIO14_beads) | C++11 | 5 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+=dp[e.first][1];
ll dif=dp[e.first][0]-dp[e.first][1]+e.second;
if(fir<=dif) sec=fir,fir=dif;
else sec=max(sec,dif);
}
dp[u][0]=max(sum,sum+fir+sec);
dp[u][1]=max(dp[u][0],sum+fir+w);
}
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));
ll ans=0;
for(int i=1;i<=n;i++) Solve(i,0,0),ans=max(ans,dp[i][0]);
printf("%lld\n",ans);
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... | ||||
