Submission #926591

# Submission time Handle Problem Language Result Execution time Memory
926591 2024-02-13T11:36:21 Z 12345678 Parkovi (COCI22_parkovi) C++17
0 / 110
341 ms 40016 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
const int nx=2e5+5;

ll n, u, v, w, k, l=1, r=2e14+5, cnt, md, ps;
vector<pair<ll, ll>> d[nx], dp(nx);
vector<int> res;

pair<ll, ll> add(pair<ll, ll> vl, ll k)
{
    pair<ll, ll> res;
    if (vl.second+k>md) res={vl.first+1, 0};
    else res={vl.first, vl.second+k};
    return res;
}

void dfs(int u, int p)
{
    for (auto [v, w]:d[u]) if (v!=p) dfs(v, u);
    if (d[u].size()==1&&u!=1) return;
    pair<ll, ll> mx={0, 0};
    for (auto [v, w]:d[u])
    {
        if (v==p) continue;
        if (w>md&&dp[v].first==1)
        {
            mx=max(mx, {1, 0});
            res.push_back(v);
            continue;
        }
        mx=max(mx, add(dp[v], w));
    }
    if (mx.first==2) dp[u]={0, 0}, res.push_back(u);
    else dp[u]=mx;
}

ll solve()
{
    for (int i=1; i<=n; i++) dp[i]={1, 0};
    res.clear();
    dfs(1, 1);
    if (dp[1].first==1) res.push_back(1);
    return res.size();
}

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>k;
    for (int i=0; i<n-1; i++) cin>>u>>v>>w, d[u].push_back({v, w}), d[v].push_back({u, w});
    while (l<r)
    {
        md=(l+r)/2;
        //cout<<md<<' '<<solve()<<'\n';
        if (solve()>k) l=md+1;
        else r=md;

    }
    //for (int i=1; i<=20; i++) md=i, cout<<i<<' '<<solve()<<'\n';
    cout<<l<<'\n';
    md=l;
    solve();
    for (auto x:res) cout<<x<<' ';
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8284 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 341 ms 37460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 328 ms 40016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8284 KB Output isn't correct
2 Halted 0 ms 0 KB -