답안 #1111302

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1111302 2024-11-12T02:26:05 Z Yang8on Parkovi (COCI22_parkovi) C++17
110 / 110
498 ms 34888 KB
#include <bits/stdc++.h>
#define Y8o "KTREE"
#define maxn (int) 2e5 + 5
#define ll long long
#define pii pair<int, int>
#define gb(i, j) ((i >> j) & 1)
#define all(x) x.begin(), x.end()
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r
#define fi(i, a, b) for(int i = a; i <= b; i ++)
#define fid(i, a, b) for(int i = a; i >= b; i --)

//#define f first
//#define s second

using namespace std;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll GetRandom(ll l, ll r) {
    return uniform_int_distribution<ll> (l, r) (rng);
}
void iof() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
    if(fopen(Y8o".inp", "r"))
    {
        freopen(Y8o".inp", "r", stdin);
//        freopen(Y8o".out", "w", stdout);
    }
}
void ctime() {
    cerr << "\n" << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}

const ll INF = 1e18;

int n, k, place;
vector<pii> o[maxn];
ll dis[maxn], reach[maxn], lim;
bool choose[maxn];

void dfs(int u = 1, int p = 0) {
    for(auto [v, w] : o[u]) if(v != p) {
        dfs(v, u);

        if(reach[v] + min(1ll * w, dis[v]) <= lim) {
            if(reach[v] + dis[v] > lim) reach[u] = max(reach[u], reach[v] + w);
            dis[u] = min(dis[u], dis[v] + w);
        }
        else {
            place ++, choose[v] = 1;
            dis[u] = min(dis[u], 1ll * w);
        }
    }
}

bool check(ll mid) {
    lim = mid, place = 0;
    fi(i, 1, n) dis[i] = INF, reach[i] = 0, choose[i] = 0;
    dfs();
    if(reach[1] + dis[1] > lim) place ++, choose[1] = 1;
    return place <= k;
}

void solve() {
    cin >> n >> k ;
    fi(i, 1, n - 1) {
        int u, v, w; cin >> u >> v >> w;
        o[u].push_back({ v, w }), o[v].push_back({ u, w });
    }

    ll l = 1, r = 2e14;
    while(l <= r) {
        ll mid = (l + r) >> 1;
        if(check(mid)) r = mid - 1;
        else l = mid + 1;
    }
    cout << l << '\n';
    check(l);
    if(place < k) {
        fi(i ,1, n) {
            if(!choose[i]) choose[i] = 1, place ++;
            if(place == k) break;
        }
    }
    fi(i, 1, n) if(choose[i]) cout << i << ' ';
}


int main() {
    iof();

    int nTest = 1;
//    cin >> nTest;

    while(nTest --) {
        solve();
    }

    ctime();
    return 0;
}

Compilation message

Main.cpp: In function 'void iof()':
Main.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen(Y8o".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8272 KB Output is correct
2 Correct 3 ms 8272 KB Output is correct
3 Correct 3 ms 8272 KB Output is correct
4 Correct 3 ms 8272 KB Output is correct
5 Correct 3 ms 8272 KB Output is correct
6 Correct 3 ms 8272 KB Output is correct
7 Correct 3 ms 8272 KB Output is correct
8 Correct 4 ms 8440 KB Output is correct
9 Correct 3 ms 8272 KB Output is correct
10 Correct 3 ms 8272 KB Output is correct
11 Correct 2 ms 8272 KB Output is correct
12 Correct 3 ms 8272 KB Output is correct
13 Correct 3 ms 8272 KB Output is correct
14 Correct 3 ms 8272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 185 ms 31828 KB Output is correct
2 Correct 190 ms 33864 KB Output is correct
3 Correct 139 ms 21284 KB Output is correct
4 Correct 360 ms 19528 KB Output is correct
5 Correct 323 ms 19276 KB Output is correct
6 Correct 314 ms 19292 KB Output is correct
7 Correct 353 ms 18248 KB Output is correct
8 Correct 467 ms 18504 KB Output is correct
9 Correct 355 ms 19032 KB Output is correct
10 Correct 358 ms 19288 KB Output is correct
11 Correct 349 ms 20812 KB Output is correct
12 Correct 371 ms 20788 KB Output is correct
13 Correct 398 ms 21928 KB Output is correct
14 Correct 346 ms 19528 KB Output is correct
15 Correct 334 ms 18932 KB Output is correct
16 Correct 373 ms 20320 KB Output is correct
17 Correct 328 ms 19628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 182 ms 30024 KB Output is correct
2 Correct 186 ms 33352 KB Output is correct
3 Correct 191 ms 32072 KB Output is correct
4 Correct 179 ms 32072 KB Output is correct
5 Correct 190 ms 34292 KB Output is correct
6 Correct 227 ms 33864 KB Output is correct
7 Correct 260 ms 34888 KB Output is correct
8 Correct 197 ms 33608 KB Output is correct
9 Correct 215 ms 33476 KB Output is correct
10 Correct 176 ms 33084 KB Output is correct
11 Correct 177 ms 31988 KB Output is correct
12 Correct 246 ms 34632 KB Output is correct
13 Correct 244 ms 34644 KB Output is correct
14 Correct 247 ms 33972 KB Output is correct
15 Correct 205 ms 32276 KB Output is correct
16 Correct 197 ms 31560 KB Output is correct
17 Correct 186 ms 31048 KB Output is correct
18 Correct 202 ms 32328 KB Output is correct
19 Correct 204 ms 32220 KB Output is correct
20 Correct 184 ms 32640 KB Output is correct
21 Correct 210 ms 32136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8272 KB Output is correct
2 Correct 3 ms 8272 KB Output is correct
3 Correct 3 ms 8272 KB Output is correct
4 Correct 3 ms 8272 KB Output is correct
5 Correct 3 ms 8272 KB Output is correct
6 Correct 3 ms 8272 KB Output is correct
7 Correct 3 ms 8272 KB Output is correct
8 Correct 4 ms 8440 KB Output is correct
9 Correct 3 ms 8272 KB Output is correct
10 Correct 3 ms 8272 KB Output is correct
11 Correct 2 ms 8272 KB Output is correct
12 Correct 3 ms 8272 KB Output is correct
13 Correct 3 ms 8272 KB Output is correct
14 Correct 3 ms 8272 KB Output is correct
15 Correct 185 ms 31828 KB Output is correct
16 Correct 190 ms 33864 KB Output is correct
17 Correct 139 ms 21284 KB Output is correct
18 Correct 360 ms 19528 KB Output is correct
19 Correct 323 ms 19276 KB Output is correct
20 Correct 314 ms 19292 KB Output is correct
21 Correct 353 ms 18248 KB Output is correct
22 Correct 467 ms 18504 KB Output is correct
23 Correct 355 ms 19032 KB Output is correct
24 Correct 358 ms 19288 KB Output is correct
25 Correct 349 ms 20812 KB Output is correct
26 Correct 371 ms 20788 KB Output is correct
27 Correct 398 ms 21928 KB Output is correct
28 Correct 346 ms 19528 KB Output is correct
29 Correct 334 ms 18932 KB Output is correct
30 Correct 373 ms 20320 KB Output is correct
31 Correct 328 ms 19628 KB Output is correct
32 Correct 182 ms 30024 KB Output is correct
33 Correct 186 ms 33352 KB Output is correct
34 Correct 191 ms 32072 KB Output is correct
35 Correct 179 ms 32072 KB Output is correct
36 Correct 190 ms 34292 KB Output is correct
37 Correct 227 ms 33864 KB Output is correct
38 Correct 260 ms 34888 KB Output is correct
39 Correct 197 ms 33608 KB Output is correct
40 Correct 215 ms 33476 KB Output is correct
41 Correct 176 ms 33084 KB Output is correct
42 Correct 177 ms 31988 KB Output is correct
43 Correct 246 ms 34632 KB Output is correct
44 Correct 244 ms 34644 KB Output is correct
45 Correct 247 ms 33972 KB Output is correct
46 Correct 205 ms 32276 KB Output is correct
47 Correct 197 ms 31560 KB Output is correct
48 Correct 186 ms 31048 KB Output is correct
49 Correct 202 ms 32328 KB Output is correct
50 Correct 204 ms 32220 KB Output is correct
51 Correct 184 ms 32640 KB Output is correct
52 Correct 210 ms 32136 KB Output is correct
53 Correct 326 ms 19456 KB Output is correct
54 Correct 498 ms 19876 KB Output is correct
55 Correct 386 ms 20368 KB Output is correct
56 Correct 350 ms 20048 KB Output is correct
57 Correct 406 ms 20332 KB Output is correct
58 Correct 375 ms 19536 KB Output is correct
59 Correct 362 ms 21320 KB Output is correct
60 Correct 402 ms 18928 KB Output is correct
61 Correct 321 ms 17976 KB Output is correct
62 Correct 314 ms 18328 KB Output is correct
63 Correct 384 ms 18892 KB Output is correct
64 Correct 396 ms 19312 KB Output is correct
65 Correct 362 ms 19272 KB Output is correct
66 Correct 444 ms 19480 KB Output is correct
67 Correct 298 ms 18660 KB Output is correct
68 Correct 389 ms 20648 KB Output is correct
69 Correct 188 ms 33612 KB Output is correct
70 Correct 164 ms 31816 KB Output is correct
71 Correct 233 ms 34448 KB Output is correct
72 Correct 134 ms 20416 KB Output is correct
73 Correct 131 ms 19640 KB Output is correct
74 Correct 162 ms 20408 KB Output is correct
75 Correct 369 ms 21064 KB Output is correct
76 Correct 348 ms 20352 KB Output is correct
77 Correct 343 ms 20504 KB Output is correct
78 Correct 322 ms 20076 KB Output is correct