답안 #884777

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
884777 2023-12-08T12:02:47 Z HossamHero7 Parkovi (COCI22_parkovi) C++14
0 / 110
58 ms 19388 KB
#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<int,int> 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

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]){
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 5976 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 49 ms 17424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 58 ms 19388 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 5976 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -