Submission #719113

# Submission time Handle Problem Language Result Execution time Memory
719113 2023-04-05T11:16:04 Z irmuun Beads and wires (APIO14_beads) C++17
28 / 100
1000 ms 1364 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[v]){
        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;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 560 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 556 KB Output is correct
8 Correct 1 ms 560 KB Output is correct
9 Correct 1 ms 560 KB Output is correct
10 Correct 1 ms 564 KB Output is correct
11 Correct 1 ms 556 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 560 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 556 KB Output is correct
8 Correct 1 ms 560 KB Output is correct
9 Correct 1 ms 560 KB Output is correct
10 Correct 1 ms 564 KB Output is correct
11 Correct 1 ms 556 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 564 KB Output is correct
15 Correct 1 ms 564 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 556 KB Output is correct
19 Correct 1 ms 556 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 2 ms 468 KB Output is correct
22 Correct 1 ms 580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 560 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 556 KB Output is correct
8 Correct 1 ms 560 KB Output is correct
9 Correct 1 ms 560 KB Output is correct
10 Correct 1 ms 564 KB Output is correct
11 Correct 1 ms 556 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 564 KB Output is correct
15 Correct 1 ms 564 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 556 KB Output is correct
19 Correct 1 ms 556 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 2 ms 468 KB Output is correct
22 Correct 1 ms 580 KB Output is correct
23 Correct 512 ms 956 KB Output is correct
24 Correct 502 ms 948 KB Output is correct
25 Correct 574 ms 948 KB Output is correct
26 Execution timed out 1074 ms 1364 KB Time limit exceeded
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 560 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 556 KB Output is correct
8 Correct 1 ms 560 KB Output is correct
9 Correct 1 ms 560 KB Output is correct
10 Correct 1 ms 564 KB Output is correct
11 Correct 1 ms 556 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 564 KB Output is correct
15 Correct 1 ms 564 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 556 KB Output is correct
19 Correct 1 ms 556 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 2 ms 468 KB Output is correct
22 Correct 1 ms 580 KB Output is correct
23 Correct 512 ms 956 KB Output is correct
24 Correct 502 ms 948 KB Output is correct
25 Correct 574 ms 948 KB Output is correct
26 Execution timed out 1074 ms 1364 KB Time limit exceeded
27 Halted 0 ms 0 KB -