답안 #851085

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
851085 2023-09-18T13:38:01 Z Itamar Paths (RMI21_paths) C++14
36 / 100
600 ms 856 KB
// greedy cat.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
using namespace std;
#include <vector>
#define ll long long
#define pll pair<ll,ll>
#define vll vector<ll>
#include <queue>
const int siz = 2000;
vector<pll> fr[siz];
ll ans[siz];
int N,K;
#include <set>
pll dfs(int i, vector<pll>&pad,multiset<pll>&s) {
    pll ansi={0,i};
    for (pll j: fr[i]) {
        if (j.first != pad[i].first) {
            pad[j.first] = { i,j.second };
            pll k =dfs(j.first, pad, s);
            s.insert({ -k.first - j.second,k.second });
            ansi = max(ansi, { k.first + j.second,k.second });

        }
    }
    return ansi;
}

void calc(int r) {
    multiset<pll> s;
    vector<pll> pad(N,{-1,-1});
    dfs(r,pad,s);
    vector<bool> vis(N);
    vis[r] = 1;
    for (int i = 0; i < K; i++) {
        if (s.empty())break;
        pll p = *s.begin();
        ans[r] -= p.first;
        ll cur = 0;
        int v = p.second;
        while (!vis[v]) {
            cur += pad[v].second;
            s.erase({ -cur, p.second });
            vis[v] = 1;
            v = pad[v].first;
        }
    }
}

int main()
{
    int n,k;
    cin >> n >> k;
    N = n, K =k;
    for (int i = 0; i < n - 1; i++) {
        int x, y, c;
        cin >> x >> y >> c;
        x--, y--;
        fr[x].push_back({ y,c });
        fr[y].push_back({ x,c });
    }
    for (int i = 0; i < n; i++) {
        calc(i);
    }
    for (int i = 0; i < n; i++)cout << ans[i] << "\n";
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 7 ms 344 KB Output is correct
4 Correct 7 ms 344 KB Output is correct
5 Correct 7 ms 348 KB Output is correct
6 Correct 8 ms 348 KB Output is correct
7 Correct 7 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 7 ms 344 KB Output is correct
4 Correct 7 ms 344 KB Output is correct
5 Correct 7 ms 348 KB Output is correct
6 Correct 8 ms 348 KB Output is correct
7 Correct 7 ms 344 KB Output is correct
8 Correct 191 ms 856 KB Output is correct
9 Correct 174 ms 692 KB Output is correct
10 Correct 216 ms 616 KB Output is correct
11 Correct 170 ms 856 KB Output is correct
12 Correct 178 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 7 ms 344 KB Output is correct
4 Correct 7 ms 344 KB Output is correct
5 Correct 7 ms 348 KB Output is correct
6 Correct 8 ms 348 KB Output is correct
7 Correct 7 ms 344 KB Output is correct
8 Correct 191 ms 856 KB Output is correct
9 Correct 174 ms 692 KB Output is correct
10 Correct 216 ms 616 KB Output is correct
11 Correct 170 ms 856 KB Output is correct
12 Correct 178 ms 600 KB Output is correct
13 Execution timed out 912 ms 728 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 7 ms 344 KB Output is correct
4 Correct 7 ms 344 KB Output is correct
5 Correct 7 ms 348 KB Output is correct
6 Correct 8 ms 348 KB Output is correct
7 Correct 7 ms 344 KB Output is correct
8 Correct 191 ms 856 KB Output is correct
9 Correct 174 ms 692 KB Output is correct
10 Correct 216 ms 616 KB Output is correct
11 Correct 170 ms 856 KB Output is correct
12 Correct 178 ms 600 KB Output is correct
13 Execution timed out 912 ms 728 KB Time limit exceeded
14 Halted 0 ms 0 KB -