| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 672648 | Hanksburger | Beads and wires (APIO14_beads) | C++17 | 3 ms | 5016 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector<pair<ll, ll> > adj[200005];
pair<ll, ll> dfs(ll u, ll p, ll x)
{
ll a[3]={0, (ll)1e18, (ll)1e18};
for (ll i=0; i<adj[u].size(); i++)
{
ll v=adj[u][i].first, w=adj[u][i].second;
if (v==p)
continue;
pair<ll, ll> r=dfs(v, u, w);
a[2]=min(a[1]+r.first, a[2]+r.second);
a[1]=min(a[0]+r.first, a[1]+r.second);
a[0]+=r.second;
}
return {min(a[0], a[2]), min(a[0]+x, a[1])};
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, sum=0;
cin >> n;
for (ll i=1; i<n; i++)
{
ll u, v, w;
cin >> u >> v >> w;
adj[u].push_back({v, w});
adj[v].push_back({u, w});
sum+=w;
}
cout << sum-dfs(1, 0, 0).first;
}Compilation message (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... | ||||
