Submission #992537

# Submission time Handle Problem Language Result Execution time Memory
992537 2024-06-04T15:58:06 Z Abito Paths (RMI21_paths) C++17
0 / 100
1 ms 604 KB
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
//#define int long long
#define y1 YONE
typedef unsigned long long ull;
using namespace std;
const int N=2005;
int n,k,dis[N],tin[N],sz[N],par[N],t,lazy[4*N+5],v[N],tree[N];
vector<pair<int,int>> adj[N];
pair<int,int> seg[4*N+5];
void dfs(int x,int p){
    par[x]=p;
    sz[x]=1;
    t++;
    tin[x]=t;
    tree[t]=x;
    for (auto u:adj[x]){
        if (p==u.F) continue;
        v[u.F]=u.S;
        dis[u.F]=dis[x]+u.S;
        dfs(u.F,x);
        sz[x]+=sz[u.F];
    }return;
}
void build(int x,int l,int r){
    lazy[x]=0;
    if (l==r){
        seg[x]={dis[tree[l]],tree[l]};
        return;
    }int mid=(l+r)/2;
    build(x*2,l,mid);
    build(x*2+1,mid+1,r);
    seg[x]=max(seg[x*2],seg[x*2+1]);
    return;
}
void push(int x){
    seg[x*2].F+=lazy[x];
    seg[x*2+1].F+=lazy[x];
    lazy[x*2]+=lazy[x];
    lazy[x*2+1]+=lazy[x];
    lazy[x]=0;
    return;
}
void edit(int x,int l,int r,int lx,int rx,int val){
    if (l>rx || r<lx) return;
    if (l>=lx && r<=rx){
        seg[x].F+=val;
        lazy[x]+=val;
        return;
    }int mid=(l+r)/2;
    push(x);
    edit(x*2,l,mid,lx,rx,val);
    edit(x*2+1,mid+1,r,lx,rx,val);
    seg[x]=max(seg[x*2],seg[x*2+1]);
    return;
}
int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    cin>>n>>k;
    for (int i=1;i<n;i++){
        int x,y,w;
        cin>>x>>y>>w;
        adj[x].pb({y,w});
        adj[y].pb({x,w});
    }
    for (int i=1;i<=n;i++){
        t=0;dis[i]=0;v[i]=0;par[i]=0;
        dfs(i,0);
        build(1,1,n);
        int ans=0;
        for (int kk=1;kk<=k;kk++){
            int x=seg[1].S;
            //cout<<x<<' ';
            while (v[x]){
                ans+=v[x];
                edit(1,1,n,tin[x],tin[x]+sz[x]-1,-v[x]);
                v[x]=0;
                x=par[x];
            }
        }//cout<<endl;
        cout<<ans<<endl;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -