Submission #198201

#TimeUsernameProblemLanguageResultExecution timeMemory
198201mehrdad_sohrabiBeads and wires (APIO14_beads)C++14
0 / 100
8 ms4984 KiB
#include <bits/stdc++.h> typedef long long int ll; typedef long double ld; #define pb push_back #define pii pair < int, int > #define F first #define S second #define int long long int #define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) #pragma GCC optimize ("Ofast") #pragma GCC optimize ("unroll-loops") #define endl '\n' using namespace std; const int N=2e5+100; vector <pii> g[N]; ll vis[N]; ll ans=0; ll dfs(ll v,ll p,ll w){ vector <int> a; for (auto u : g[v]){ if (u.F==p) continue; dfs(u.F,v,u.S); if (vis[u.F]) continue; a.pb(u.S); } sort(a.begin(),a.end()); reverse(a.begin(),a.end()); if (p!=-1 && a.size()){ ans+=a[0]+w; vis[v]=1; } } int32_t main(){ ll n; cin >> n; for (int i=0;i<n-1;i++){ ll u,v,w; cin >> u >> v >> w; g[u].pb({v,w}); g[v].pb({u,w}); } ll ma=0; for (int i=1;i<=n;i++){ ans=0; dfs(i,-1,0); ma=max(ma,ans); } cout << ma << endl; }

Compilation message (stderr)

beads.cpp: In function 'll dfs(ll, ll, ll)':
beads.cpp:32:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...