# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
338105 | ogibogi2004 | Beads and wires (APIO14_beads) | C++14 | 1096 ms | 5484 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll MAXN=2e5+6;
const ll INF=2e15;
ll dp[MAXN][2];
ll par[MAXN];
vector<pair<ll,ll> >g[MAXN];
void dfs(ll u,ll p)
{
par[u]=p;
vector<pair<pair<ll,ll>,ll> >ch;
for(auto v:g[u])
{
if(v.first==p)continue;
dfs(v.first,u);
ch.push_back({{dp[v.first][0],dp[v.first][1]},v.second});
}
dp[u][1]=-INF;
for(ll i=0;i<ch.size();i++)
{
dp[u][0]+=max(ch[i].first.first,ch[i].first.second+ch[i].second);
}
for(ll i=0;i<ch.size();i++)
{
dp[u][1]=max(dp[u][1],dp[u][0]-max(ch[i].first.first,ch[i].first.second+ch[i].second)+ch[i].first.first+ch[i].second);
}
}
int main()
{
ll n;
cin>>n;
for(ll i=1;i<n;i++)
{
ll x,y,z;
cin>>x>>y>>z;
g[x].push_back({y,z});
g[y].push_back({x,z});
}
ll ans=0;
for(ll i=1;i<=n;i++)
{
for(ll j=1;j<=n;j++)
{
dp[j][0]=0;
dp[j][1]=-INF;
}
dfs(i,0);
//cout<<i<<" "<<dp[i][0]<<endl;
ans=max(ans,dp[i][0]);
}
cout<<ans<<endl;
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) 메시지
# | 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... |