Submission #854071

# Submission time Handle Problem Language Result Execution time Memory
854071 2023-09-26T05:01:43 Z ivaaaaaaan Paths (RMI21_paths) C++17
0 / 100
1 ms 604 KB
#include <bits/stdc++.h>

using namespace std;

const long long max_size = 2e3 + 1;

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

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

signed main ()
{
    ios_base::sync_with_stdio(false);
    long long n, k;
    cin >> n >> k;
    for (long long i = 1; i < n; i++)
    {
        long long x, y, c;
        cin >> x >> y >> c;
        dog[i] = c;
        mc[x].push_back({y, i});
        mc[y].push_back({x, i});
    }
    for (long long i = 1; i <= n; i++)
    {
        for (long long j = 1; j < n; j++)
        {
            d[j] = dog[j];
        }
        long long ans = 0;
        for (long long j = 1; j <= k; j++)
        {
            dp[i] = 0;
            dfs(i, 0);
            long long idx = 0, mx = -1;
            for (long long tt = 1; tt <= n; tt++)
            {
               // cout << j << " " << dp[tt] << '\n';
                if (dp[tt] > mx)
                {
                    mx = dp[tt];
                    idx = tt;
                }
            }
         //   cout << '\n';
            ans += mx;
            long long nod = idx;
            while (nod != 0)
            {
                d[t[nod].second] = 0;
                nod = t[nod].first;
            }
        }
        cout << ans << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 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 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -