Submission #717348

# Submission time Handle Problem Language Result Execution time Memory
717348 2023-04-01T21:19:01 Z vjudge1 Paths (RMI21_paths) C++17
0 / 100
1 ms 488 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #define int long long
#define endl '\n'
using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>;
vector<pair<int,int>>vct[1001];
int mp[1001][1001];
vector<bool>bol(1001);
int ans,n,in=1;
bool GG;
void slv(){
    deque<pair<int,int>>pq={{0,in}};
    vector<int>vis(n+1);
    int g=0;
    vis[in]=in;
    while(pq.size()){
        int a=pq.front().second,b=pq.front().first;
        pq.pop_front();
        if(b>=g){
            g=b;
            in=a;
        }
        for(auto &i:vct[a]){
            if(!vis[i.first]){
                vis[i.first]=a;
                pq.push_back({b+mp[a][i.first],i.first});
            }
        }
    }
    int I=in;
    while(vis[I]!=I){
        if(GG)bol[I]=1;
        ans+=mp[vis[I]][I];
        mp[vis[I]][I]=0;
        mp[I][vis[I]]=0;
        I=vis[I];
    }
    if(GG)bol[I]=1;
}
void resett(){
    for(int j=1;j<=n;j++){
        for(auto &z:vct[j]){
            mp[j][z.first]=z.second;
        }
    }
}
signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int k;
    cin>>n>>k;
    for(int i=1;i<n;i++){
        int a,b,c;
        cin>>a>>b>>c;
        vct[a].push_back({b,c});
        vct[b].push_back({a,c});
    }
    int K=k;
    int g=0;
    in=1;
    resett();
    slv();
    resett();
    ans=0;
    GG=1;
    while(k--)slv();
    GG=0;
    g=ans;
    for(int w=1;w<=n;w++){
        if(bol[w]){
            cout<<g<<endl;
            continue;
        }
        ans=0;
        in=w;
        resett();
        k=K;
        while(k--)slv();
        if(w==1)g=ans;
        cout<<ans<<endl;
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 488 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -