Submission #717328

# Submission time Handle Problem Language Result Execution time Memory
717328 2023-04-01T20:33:37 Z vjudge1 Paths (RMI21_paths) C++17
56 / 100
291 ms 676 KB
#include <bits/stdc++.h>
#include <fstream>
#define endl '\n'
#define mod 998244353
#define INF 1000000000000000000
#define ll long long
///#define cin fin
///#define cout fout
#define fi first
#define se second
using namespace std;
///ofstream fout("herding.out");
///ifstream fin("herding.in");
const int N = 2e3 + 5;
vector<pair<int,long long>> v[N];
long long mx[N];
priority_queue<long long> pq;

void dfs(int s, int p) {
    pair<int,long long> fin = {-1,-1};

    for(auto i : v[s]) {
        if(i.first != p) { dfs(i.first,s);
        if(fin.second < mx[i.first]+i.second) {
            fin.first = i.first;
            fin.second = mx[i.first]+i.second;
        }
        }
    }
    for(auto i : v[s]) {
        if(i.first != p && i.first != fin.first) {
            pq.push(mx[i.first]+i.second);
        }
    }
    if(fin.second != -1) mx[s] = fin.second;
    if(p == 0) pq.push(fin.second);
}

int main()
{
    ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
    int n, k; cin >> n >> k;
    for(int i = 0; i < n-1; i++) {
        int a, b, c; cin >> a >> b >> c;
        v[a].push_back({b,c});
        v[b].push_back({a,c});
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) mx[j] = 0;
        while(!pq.empty())pq.pop();
        long long ans = 0; int num = k;
        dfs(i,0);
        while(num != 0 && !pq.empty()) {
            ans += pq.top();
            pq.pop(); num--;
        }
        cout << ans << endl;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 65 ms 436 KB Output is correct
9 Correct 46 ms 548 KB Output is correct
10 Correct 26 ms 488 KB Output is correct
11 Correct 62 ms 448 KB Output is correct
12 Correct 34 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 65 ms 436 KB Output is correct
9 Correct 46 ms 548 KB Output is correct
10 Correct 26 ms 488 KB Output is correct
11 Correct 62 ms 448 KB Output is correct
12 Correct 34 ms 468 KB Output is correct
13 Correct 291 ms 588 KB Output is correct
14 Correct 227 ms 676 KB Output is correct
15 Correct 118 ms 592 KB Output is correct
16 Correct 277 ms 672 KB Output is correct
17 Correct 161 ms 544 KB Output is correct
18 Correct 148 ms 544 KB Output is correct
19 Correct 279 ms 648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 65 ms 436 KB Output is correct
9 Correct 46 ms 548 KB Output is correct
10 Correct 26 ms 488 KB Output is correct
11 Correct 62 ms 448 KB Output is correct
12 Correct 34 ms 468 KB Output is correct
13 Correct 291 ms 588 KB Output is correct
14 Correct 227 ms 676 KB Output is correct
15 Correct 118 ms 592 KB Output is correct
16 Correct 277 ms 672 KB Output is correct
17 Correct 161 ms 544 KB Output is correct
18 Correct 148 ms 544 KB Output is correct
19 Correct 279 ms 648 KB Output is correct
20 Runtime error 1 ms 468 KB Execution killed with signal 11
21 Halted 0 ms 0 KB -