Submission #884778

#TimeUsernameProblemLanguageResultExecution timeMemory
884778HossamHero7Parkovi (COCI22_parkovi)C++14
0 / 110
55 ms15184 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define endl '\n' const int N = 2e5 + 5; vector<pair<int,ll>> adj[N]; ll dp_down[N] , dp_up[N]; void dfs(int node,int par){ pair<ll,ll> mx{0,0}; for(auto [ch,c] : adj[node]){ if(ch == par) continue; dfs(ch,node); dp_down[node] = max(dp_down[node] , dp_down[ch]+c); if(mx.first < dp_down[ch]) { swap(mx.first,mx.second); mx.first = dp_down[ch]; } else if(mx.second < dp_down[ch]){ mx.second = dp_down[ch]; } } for(auto [ch,c] : adj[node]){ if(ch == par) continue; ll x = 0; if(mx.first == dp_down[ch]) x = mx.second; else x = mx.first; dp_up[ch] = max(dp_up[node] , x); } } void solve(){ int n,k; cin>>n>>k; for(int i=0;i<n-1;i++){ int a,b,c; cin>>a>>b>>c; adj[a].push_back({b,c}); adj[b].push_back({a,c}); } pair<ll,int> ans = {1e18,0}; for(int i=1;i<=n;i++) ans = min(ans , {max(dp_down[i] , dp_up[i]),i}); cout<<ans.first<<endl<<ans.second<<endl; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t=1; //cin>>t; while(t--){ solve(); } return 0; }

Compilation message (stderr)

Main.cpp: In function 'void dfs(int, int)':
Main.cpp:10:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   10 |     for(auto [ch,c] :  adj[node]){
      |              ^
Main.cpp:22:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   22 |     for(auto [ch,c] : adj[node]){
      |              ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...