Submission #672649

#TimeUsernameProblemLanguageResultExecution timeMemory
672649HanksburgerBeads and wires (APIO14_beads)C++17
0 / 100
3 ms4948 KiB
#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(min(a[0], a[2])+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)

beads.cpp: In function 'std::pair<long long int, long long int> dfs(long long int, long long int, long long int)':
beads.cpp:8:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |     for (ll i=0; i<adj[u].size(); i++)
      |                  ~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...