답안 #973358

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
973358 2024-05-01T20:05:54 Z Circling Parkovi (COCI22_parkovi) C++17
10 / 110
423 ms 38736 KB
/*The British Royal Family and a small cadre of English Fabian Socialists, in
conjunction with the Rockefellers and the Rothchilds, are engaged in a
conspiracy to greatly reduce the population of the human race in order to head
off a Malthusian catastrophe, a catastrophe that could easily be avoided by
simply building a massive amount of nuclear power plants and a number of massive
superhighways and bridges to connect all of the world's continents. But doing
that would cut into the conspiracy's profits. So the British Royal Family
invented environmentalism and neoliberalism in order to hide the truth. And in
order to further reduce the population, the British Royal Family is also the
world's foremost drug trafficking conspiracy. And it uses its control of the IMF
to push austerity in order to kill as many people in the global south as
possible.
And also Henry Kissinger is a gay KGB agent. */
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;


int64_t n, k, a, b, w, mind, maxd, midd;
vector<vector<pair<int, int64_t>>> graph;
set<int> placed;


pair<int64_t, int64_t> dfs(int node, int prev){
    int64_t parkless = 0, stparkrange = -1;
    pair<int, int> childans;
    for (pair<int, int64_t> child: graph[node]){
        if (child.first == prev) continue;
        childans = dfs(child.first, node);
        if (childans.first != -1 && childans.first + child.second > midd){
            placed.insert(child.first);
            childans = {-1, midd};
        }
        if (childans.first != -1) parkless = max(parkless, childans.first + child.second);
        stparkrange = max(stparkrange, childans.second - child.second);
    }
    if (parkless <= stparkrange) return {-1, stparkrange};
    if (parkless > midd || node == 1){
        placed.insert(node);
        return {-1, midd};
    }
    return {parkless, stparkrange};
}


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin >> n >> k;
    graph.resize(n + 1);
    for (int i = 1; i < n; i++){
        cin >> a >> b >> w;
        graph[a].push_back({b, w});
        graph[b].push_back({a, w});
    }
    mind = 0;
    maxd = 200000000000000ll;
    while (mind != maxd){
        midd = (mind + maxd) / 2;
        placed.clear();
        dfs(1, 0);
        if (placed.size() <= k) maxd = midd;
        else mind = midd + 1;
    }
    midd = mind;
    placed.clear();
    dfs(1, 0);
    for (int i = 1; placed.size() < k; i++) placed.insert(i);
    cout << midd << '\n';
    for (int i: placed) cout << i << ' ';
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:68:27: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int64_t' {aka 'long int'} [-Wsign-compare]
   68 |         if (placed.size() <= k) maxd = midd;
      |             ~~~~~~~~~~~~~~^~~~
Main.cpp:74:35: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int64_t' {aka 'long int'} [-Wsign-compare]
   74 |     for (int i = 1; placed.size() < k; i++) placed.insert(i);
      |                     ~~~~~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 394 ms 36944 KB Output is correct
2 Incorrect 410 ms 38136 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 423 ms 38736 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 394 ms 36944 KB Output is correct
16 Incorrect 410 ms 38136 KB Output isn't correct
17 Halted 0 ms 0 KB -