Submission #854294

# Submission time Handle Problem Language Result Execution time Memory
854294 2023-09-26T16:37:29 Z ivaaaaaaan Paths (RMI21_paths) C++17
56 / 100
206 ms 792 KB
#include <bits/stdc++.h>

using namespace std;

struct str
{
    long long x, idx;
    bool operator < (const str & aux) const
    {
        return x < aux.x;
    }
};

const long long max_size = 2e3 + 1;

vector <pair <long long, long long>> mc[max_size];
long long dp[max_size], best[max_size], t[max_size];

void dfs (long long nod, long long par, long long val)
{
    dp[nod] = 0;
    best[nod] = 0;
    for (auto f : mc[nod])
    {
        if (f.first == par)
        {
            continue;
        }
        dfs(f.first, nod, f.second);
        if (dp[nod] < dp[f.first])
        {
            dp[nod] = dp[f.first];
            best[nod] = f.first;
        }
    }
    dp[nod] += val;
}

void dfs2 (long long nod, long long par, long long cap)
{
    t[nod] = cap;
    if (best[nod] == 0)
    {
        return;
    }
    dfs2(best[nod], nod, cap);
    for (auto f : mc[nod])
    {
        if (f.first == best[nod] || f.first == par)
        {
            continue;
        }
        dfs2(f.first, nod, f.first);
    }
}

signed main ()
{
    long long n, k;
    cin >> n >> k;
    for (long long i = 1; i < n; i++)
    {
        long long x, y, c;
        cin >> x >> y >> c;
        mc[x].push_back({y, c});
        mc[y].push_back({x, c});
    }
    for (long long i = 1; i <= n; i++)
    {
        long long ans = 0;
        t[i] = 0;
        dfs(i, 0, 0);
        dfs2(i, 0, i);
        priority_queue <str> pq;
        for (long long j = 1; j <= n; j++)
        {
            if (t[j] == j)
            {
                pq.push({dp[j], j});
            }
        }
        for (long long j = 1; j <= k; j++)
        {
            if (pq.empty())
            {
                break;
            }
            ans += pq.top().x;
            pq.pop();
        }
        cout << ans;
        if (i < n)
        {
            cout << '\n';
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 600 KB Output is correct
4 Correct 2 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 600 KB Output is correct
4 Correct 2 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 30 ms 600 KB Output is correct
9 Correct 24 ms 600 KB Output is correct
10 Correct 21 ms 768 KB Output is correct
11 Correct 25 ms 600 KB Output is correct
12 Correct 24 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 600 KB Output is correct
4 Correct 2 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 30 ms 600 KB Output is correct
9 Correct 24 ms 600 KB Output is correct
10 Correct 21 ms 768 KB Output is correct
11 Correct 25 ms 600 KB Output is correct
12 Correct 24 ms 604 KB Output is correct
13 Correct 188 ms 600 KB Output is correct
14 Correct 144 ms 792 KB Output is correct
15 Correct 93 ms 600 KB Output is correct
16 Correct 158 ms 728 KB Output is correct
17 Correct 123 ms 692 KB Output is correct
18 Correct 85 ms 604 KB Output is correct
19 Correct 206 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 600 KB Output is correct
4 Correct 2 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 30 ms 600 KB Output is correct
9 Correct 24 ms 600 KB Output is correct
10 Correct 21 ms 768 KB Output is correct
11 Correct 25 ms 600 KB Output is correct
12 Correct 24 ms 604 KB Output is correct
13 Correct 188 ms 600 KB Output is correct
14 Correct 144 ms 792 KB Output is correct
15 Correct 93 ms 600 KB Output is correct
16 Correct 158 ms 728 KB Output is correct
17 Correct 123 ms 692 KB Output is correct
18 Correct 85 ms 604 KB Output is correct
19 Correct 206 ms 600 KB Output is correct
20 Runtime error 1 ms 600 KB Execution killed with signal 11
21 Halted 0 ms 0 KB -