Submission #770008

# Submission time Handle Problem Language Result Execution time Memory
770008 2023-06-30T16:26:09 Z vjudge1 Paths (RMI21_paths) C++17
0 / 100
600 ms 9888 KB
//YOU WILL MAKE IT
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#include<bits/stdc++.h>
using namespace std;
const int N=2e5;
vector<pair<int,int>> tree[N];
priority_queue<long long> pq;
void dfs(int i,int p,int sum){
    pq.push(sum);
    for(auto w:tree[i]){
        if(w.first==p) continue;
        dfs(w.first,i,sum+w.second);
    }
}
void solve(){
     int k,n;cin>>n>>k;
     int val=n;
     n--;
     while(n--){
        int a,b,w;cin>>a>>b>>w;
        tree[a].push_back({b,w});
        tree[b].push_back({a,w});
     }
     for(int i=1;i<=val;i++){
        dfs(i,-1,0);
        long long ans=0;
        int cur=k;
        while(!pq.empty()){
            if(cur>0)
             ans+=pq.top();
            pq.pop();
            cur--;
        }
        cout<<ans<<endl;
     }

}
int main(){
   /* freopen("hopscotch.in","r",stdin);
     freopen("hopscotch.out","w",stdout);*/
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
   int t=1;
   // cin>>t;
    while(t--){
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1047 ms 9888 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -