Submission #719112

# Submission time Handle Problem Language Result Execution time Memory
719112 2023-04-05T11:15:42 Z irmuun Beads and wires (APIO14_beads) C++17
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>

using namespace std;

#define pb push_back
#define ll long long
#define ff first
#define ss second
#define all(s) s.begin(),s.end()

const ll N=10005;
ll dp[2][N];
vector<pair<ll,ll>>adj[N];
void dfs(ll v,ll par){
    for(auto [u,w]:adj[u]){
        if(u!=par){
            dp[1][u]=w;
            dfs(u,v);
            dp[0][v]=max(dp[0][v]+dp[0][u],dp[1][v]+dp[1][u]);
            dp[1][v]+=dp[0][u];
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll n;
    cin>>n;
    for(ll i=1;i<n;i++){
        ll u,v,w;
        cin>>u>>v>>w;
        adj[u].pb({v,w});
        adj[v].pb({u,w});
    }
    
    ll ans=0;
    for(ll i=1;i<=n;i++){
        fill(dp[0],dp[0]+n+1,0);
        fill(dp[1],dp[1]+n+1,0);
        dfs(i,-1);
        ans=max(ans,dp[1][i]);
    }
    cout<<ans;
}

Compilation message

beads.cpp: In function 'void dfs(long long int, long long int)':
beads.cpp:15:24: error: 'u' was not declared in this scope
   15 |     for(auto [u,w]:adj[u]){
      |                        ^