답안 #696707

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
696707 2023-02-07T05:39:44 Z bachhoangxuan Parkovi (COCI22_parkovi) C++17
110 / 110
1167 ms 35652 KB
// Judges with GCC >= 12 only needs Ofast
// #pragma GCC optimize("O3,no-stack-protector,fast-math,unroll-loops,tree-vectorize")
// MLE optimization
// #pragma GCC optimize("conserve-stack")
// Old judges
// #pragma GCC target("sse4.2,popcnt,lzcnt,abm,mmx,fma,bmi,bmi2")
// New judges. Test with assert(__builtin_cpu_supports("avx2"));
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
// Atcoder
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
#include<bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_real_distribution<> pp(0.0,1.0);
#define int long long
#define ld long double
#define pii pair<int,int>
#define piii pair<int,pii>
#define fi first
#define se second
const int inf=1e18;
const int mod=998244353;
const int mod2=1e9+7;
const int maxn=200005;
const int maxq=500005;
const int maxl=20;
const int maxa=1000005;
int power(int a,int n){
    int res=1;
    while(n){
        if(n&1) res=res*a%mod;
        a=a*a%mod;n>>=1;
    }
    return res;
}
int n,k,ans=0,num=0,mid;
vector<pii> edge[maxn];
vector<int> cur,res;
bool used[maxn];
pii dfs(int u,int par,int len){
    int park=inf,Max=0;
    for(pii v:edge[u]){
        if(v.first==par) continue;
        pii x=dfs(v.first,u,v.second);
        park=min(park,x.first+v.second);
        Max=max(Max,x.second+v.second);
    }
    if(Max+park<=mid) return {park,-inf};
    else if(Max+len<=mid){
        if(par==0){
            num++;cur.push_back(u);
            return {-1,-1};
        }
        else return {park,Max};
    }
    else{num++;cur.push_back(u);return {0,-inf};}
}
bool check(){
    cur.clear();
    num=0;dfs(1,0,0);
    return (num<=k);
}
void solve(){
    cin >> n >> k;
    for(int i=1;i<n;i++){
        int u,v,w;cin >> u >> v >> w;
        edge[u].push_back({v,w});
        edge[v].push_back({u,w});
    }
    int l=1,r=1e16,ans=r;
    while(r>=l){
        mid=(r+l)>>1;
        if(check()){ans=mid;res=cur;r=mid-1;}
        else l=mid+1;
    }
    cout << ans << '\n';
    for(int v:res) used[v]=true;
    for(int i=1;i<=n;i++){
        if((int)res.size()==k || used[i]) continue;
        res.push_back(i);
    }
    for(int v:res) cout << v << ' ';
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int test=1;//cin >> test;
    while(test--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 5028 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 4 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 3 ms 5004 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 269 ms 28488 KB Output is correct
2 Correct 305 ms 29888 KB Output is correct
3 Correct 326 ms 16660 KB Output is correct
4 Correct 1031 ms 15504 KB Output is correct
5 Correct 1031 ms 15088 KB Output is correct
6 Correct 964 ms 15092 KB Output is correct
7 Correct 899 ms 15304 KB Output is correct
8 Correct 1076 ms 15692 KB Output is correct
9 Correct 922 ms 15520 KB Output is correct
10 Correct 1008 ms 15640 KB Output is correct
11 Correct 696 ms 16716 KB Output is correct
12 Correct 664 ms 16696 KB Output is correct
13 Correct 732 ms 17836 KB Output is correct
14 Correct 613 ms 16768 KB Output is correct
15 Correct 618 ms 16272 KB Output is correct
16 Correct 660 ms 16896 KB Output is correct
17 Correct 628 ms 16256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 298 ms 29560 KB Output is correct
2 Correct 295 ms 30348 KB Output is correct
3 Correct 284 ms 29224 KB Output is correct
4 Correct 270 ms 29056 KB Output is correct
5 Correct 335 ms 35652 KB Output is correct
6 Correct 347 ms 34128 KB Output is correct
7 Correct 350 ms 35600 KB Output is correct
8 Correct 303 ms 31096 KB Output is correct
9 Correct 327 ms 30888 KB Output is correct
10 Correct 293 ms 30412 KB Output is correct
11 Correct 294 ms 29388 KB Output is correct
12 Correct 357 ms 35444 KB Output is correct
13 Correct 375 ms 34748 KB Output is correct
14 Correct 358 ms 32896 KB Output is correct
15 Correct 297 ms 30144 KB Output is correct
16 Correct 268 ms 29276 KB Output is correct
17 Correct 286 ms 29084 KB Output is correct
18 Correct 310 ms 30384 KB Output is correct
19 Correct 287 ms 32916 KB Output is correct
20 Correct 309 ms 32800 KB Output is correct
21 Correct 297 ms 31784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 3 ms 5028 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 4 ms 4948 KB Output is correct
11 Correct 3 ms 4948 KB Output is correct
12 Correct 2 ms 4948 KB Output is correct
13 Correct 3 ms 5004 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 269 ms 28488 KB Output is correct
16 Correct 305 ms 29888 KB Output is correct
17 Correct 326 ms 16660 KB Output is correct
18 Correct 1031 ms 15504 KB Output is correct
19 Correct 1031 ms 15088 KB Output is correct
20 Correct 964 ms 15092 KB Output is correct
21 Correct 899 ms 15304 KB Output is correct
22 Correct 1076 ms 15692 KB Output is correct
23 Correct 922 ms 15520 KB Output is correct
24 Correct 1008 ms 15640 KB Output is correct
25 Correct 696 ms 16716 KB Output is correct
26 Correct 664 ms 16696 KB Output is correct
27 Correct 732 ms 17836 KB Output is correct
28 Correct 613 ms 16768 KB Output is correct
29 Correct 618 ms 16272 KB Output is correct
30 Correct 660 ms 16896 KB Output is correct
31 Correct 628 ms 16256 KB Output is correct
32 Correct 298 ms 29560 KB Output is correct
33 Correct 295 ms 30348 KB Output is correct
34 Correct 284 ms 29224 KB Output is correct
35 Correct 270 ms 29056 KB Output is correct
36 Correct 335 ms 35652 KB Output is correct
37 Correct 347 ms 34128 KB Output is correct
38 Correct 350 ms 35600 KB Output is correct
39 Correct 303 ms 31096 KB Output is correct
40 Correct 327 ms 30888 KB Output is correct
41 Correct 293 ms 30412 KB Output is correct
42 Correct 294 ms 29388 KB Output is correct
43 Correct 357 ms 35444 KB Output is correct
44 Correct 375 ms 34748 KB Output is correct
45 Correct 358 ms 32896 KB Output is correct
46 Correct 297 ms 30144 KB Output is correct
47 Correct 268 ms 29276 KB Output is correct
48 Correct 286 ms 29084 KB Output is correct
49 Correct 310 ms 30384 KB Output is correct
50 Correct 287 ms 32916 KB Output is correct
51 Correct 309 ms 32800 KB Output is correct
52 Correct 297 ms 31784 KB Output is correct
53 Correct 976 ms 14924 KB Output is correct
54 Correct 1012 ms 15208 KB Output is correct
55 Correct 1086 ms 15536 KB Output is correct
56 Correct 991 ms 16000 KB Output is correct
57 Correct 1110 ms 17896 KB Output is correct
58 Correct 986 ms 15012 KB Output is correct
59 Correct 1059 ms 21404 KB Output is correct
60 Correct 995 ms 15828 KB Output is correct
61 Correct 936 ms 14748 KB Output is correct
62 Correct 959 ms 17248 KB Output is correct
63 Correct 1062 ms 15676 KB Output is correct
64 Correct 1000 ms 19492 KB Output is correct
65 Correct 1058 ms 15452 KB Output is correct
66 Correct 1028 ms 17812 KB Output is correct
67 Correct 952 ms 14764 KB Output is correct
68 Correct 1167 ms 21260 KB Output is correct
69 Correct 311 ms 29452 KB Output is correct
70 Correct 270 ms 28248 KB Output is correct
71 Correct 368 ms 33104 KB Output is correct
72 Correct 216 ms 15848 KB Output is correct
73 Correct 226 ms 14992 KB Output is correct
74 Correct 227 ms 19184 KB Output is correct
75 Correct 632 ms 16840 KB Output is correct
76 Correct 706 ms 17196 KB Output is correct
77 Correct 656 ms 16724 KB Output is correct
78 Correct 644 ms 18148 KB Output is correct