답안 #869082

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
869082 2023-11-03T05:55:24 Z Mr_Ph Parkovi (COCI22_parkovi) C++14
110 / 110
1341 ms 51832 KB
#include<bits/stdc++.h>
#pragma GCC optimize ("Ofast")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
typedef long long int lli;
typedef unsigned long long ull;
using namespace std;
using namespace __gnu_pbds;
template<class x>
using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>;
ll mod=(ll)1e9+7;
ll mod1=998244353;
///the defines :)
#define endl '\n'
#define vi vector<int>
#define vll vector<ll>
#define ent(arr) for(int i=0;i<arr.size();i++)cin>>arr[i];
#define all(arr) arr.begin(),arr.end()
#define allr(arr) arr.rbegin(),arr.rend()
#define sz size()
#define int long long
vector<vector<pair<int,int>>>adj;
vector<int>cpark;
vector<int>fpark;
int curk;
vi xd;
void dfs(int node,int parent,int mid,int prv)
{
    for(auto i:adj[node])
    {
		if (i.first == parent) continue;
			dfs(i.first,node,mid,i.second);
			cpark[node]=min(cpark[node],cpark[i.first]+i.second);
			fpark[node]=max(fpark[node],fpark[i.first]+i.second);
	}
	if(cpark[node]>mid)
        fpark[node]=max(0ll,fpark[node]);
	if(fpark[node]+cpark[node]<=mid){
	    fpark[node]=-1e15;
		return;
	}
	if (fpark[node]+prv>mid)
	{
		xd.push_back(node);
		curk++;
		fpark[node]=-1e15;
		cpark[node]=0;
	}
    else if(node==1&&fpark[node]>=0)
    {
        curk++;
        xd.push_back(node);
    }
}
void preprocess() {}
void solve()
{
    int n,k;
    cin>>n>>k;
    adj.resize(n+1);
    cpark.resize(n+1);
    fpark.resize(n+1);
    for(int i=1; i<n; i++)
    {
        int a,b,c;
        cin>>a>>b>>c;
        adj[a].push_back({b,c});
        adj[b].push_back({a,c});
    }
    int l=1,r=1e15;
    int ans=0;
    vi ans1;
    vi lol;
    while(l<=r)
    {
        int mid=(l+r)/2;
        curk=0;
        xd=lol;
        for(int i=1; i<=n; i++)
            cpark[i]=1e15,fpark[i]=-1e15;
        dfs(1,0,mid,0);
        if(curk<=k)
        {
            ans=mid;
            ans1=xd;
            r=mid-1;
        }
        else
            l=mid+1;
    }
    cout<<ans<<endl;
    map<int,int>mp;
    for(auto i:ans1)
    {
        mp[i]++;
        cout<<i<<" ";
    }
    int cnt=ans1.sz;
    for(int i=1; i<=n; i++)
    {
        if(!mp[i]&&cnt<k)
        {
            cnt++;
            cout<<i<<" ";
        }
    }
    cout<<endl;
}
signed main()
{
    // freopen("meta_game_input.txt","r",stdin);
    // freopen("otput.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    preprocess();
    //bla();
    int t=1;
    //cin>>t;
    while(t--)
        solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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 1 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 0 ms 348 KB Output is correct
12 Correct 0 ms 456 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 316 ms 42792 KB Output is correct
2 Correct 326 ms 44132 KB Output is correct
3 Correct 340 ms 30456 KB Output is correct
4 Correct 836 ms 28908 KB Output is correct
5 Correct 740 ms 28108 KB Output is correct
6 Correct 833 ms 28132 KB Output is correct
7 Correct 658 ms 28624 KB Output is correct
8 Correct 1020 ms 29916 KB Output is correct
9 Correct 891 ms 28940 KB Output is correct
10 Correct 929 ms 29596 KB Output is correct
11 Correct 668 ms 30700 KB Output is correct
12 Correct 688 ms 29868 KB Output is correct
13 Correct 795 ms 32564 KB Output is correct
14 Correct 581 ms 29760 KB Output is correct
15 Correct 658 ms 29288 KB Output is correct
16 Correct 609 ms 30292 KB Output is correct
17 Correct 575 ms 29264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 356 ms 44704 KB Output is correct
2 Correct 336 ms 43548 KB Output is correct
3 Correct 294 ms 41444 KB Output is correct
4 Correct 323 ms 41368 KB Output is correct
5 Correct 381 ms 46920 KB Output is correct
6 Correct 444 ms 45468 KB Output is correct
7 Correct 406 ms 48408 KB Output is correct
8 Correct 331 ms 45136 KB Output is correct
9 Correct 367 ms 44620 KB Output is correct
10 Correct 322 ms 43844 KB Output is correct
11 Correct 309 ms 42336 KB Output is correct
12 Correct 418 ms 48684 KB Output is correct
13 Correct 407 ms 51832 KB Output is correct
14 Correct 399 ms 50196 KB Output is correct
15 Correct 314 ms 46676 KB Output is correct
16 Correct 329 ms 44628 KB Output is correct
17 Correct 298 ms 44628 KB Output is correct
18 Correct 372 ms 46928 KB Output is correct
19 Correct 341 ms 48220 KB Output is correct
20 Correct 367 ms 49188 KB Output is correct
21 Correct 352 ms 47804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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 1 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 0 ms 348 KB Output is correct
12 Correct 0 ms 456 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 316 ms 42792 KB Output is correct
16 Correct 326 ms 44132 KB Output is correct
17 Correct 340 ms 30456 KB Output is correct
18 Correct 836 ms 28908 KB Output is correct
19 Correct 740 ms 28108 KB Output is correct
20 Correct 833 ms 28132 KB Output is correct
21 Correct 658 ms 28624 KB Output is correct
22 Correct 1020 ms 29916 KB Output is correct
23 Correct 891 ms 28940 KB Output is correct
24 Correct 929 ms 29596 KB Output is correct
25 Correct 668 ms 30700 KB Output is correct
26 Correct 688 ms 29868 KB Output is correct
27 Correct 795 ms 32564 KB Output is correct
28 Correct 581 ms 29760 KB Output is correct
29 Correct 658 ms 29288 KB Output is correct
30 Correct 609 ms 30292 KB Output is correct
31 Correct 575 ms 29264 KB Output is correct
32 Correct 356 ms 44704 KB Output is correct
33 Correct 336 ms 43548 KB Output is correct
34 Correct 294 ms 41444 KB Output is correct
35 Correct 323 ms 41368 KB Output is correct
36 Correct 381 ms 46920 KB Output is correct
37 Correct 444 ms 45468 KB Output is correct
38 Correct 406 ms 48408 KB Output is correct
39 Correct 331 ms 45136 KB Output is correct
40 Correct 367 ms 44620 KB Output is correct
41 Correct 322 ms 43844 KB Output is correct
42 Correct 309 ms 42336 KB Output is correct
43 Correct 418 ms 48684 KB Output is correct
44 Correct 407 ms 51832 KB Output is correct
45 Correct 399 ms 50196 KB Output is correct
46 Correct 314 ms 46676 KB Output is correct
47 Correct 329 ms 44628 KB Output is correct
48 Correct 298 ms 44628 KB Output is correct
49 Correct 372 ms 46928 KB Output is correct
50 Correct 341 ms 48220 KB Output is correct
51 Correct 367 ms 49188 KB Output is correct
52 Correct 352 ms 47804 KB Output is correct
53 Correct 813 ms 33112 KB Output is correct
54 Correct 834 ms 33784 KB Output is correct
55 Correct 1341 ms 35424 KB Output is correct
56 Correct 1096 ms 34816 KB Output is correct
57 Correct 1040 ms 36300 KB Output is correct
58 Correct 940 ms 33136 KB Output is correct
59 Correct 1109 ms 38824 KB Output is correct
60 Correct 948 ms 33648 KB Output is correct
61 Correct 755 ms 31076 KB Output is correct
62 Correct 905 ms 32948 KB Output is correct
63 Correct 826 ms 33804 KB Output is correct
64 Correct 775 ms 35984 KB Output is correct
65 Correct 975 ms 33532 KB Output is correct
66 Correct 937 ms 34676 KB Output is correct
67 Correct 763 ms 31964 KB Output is correct
68 Correct 1100 ms 38520 KB Output is correct
69 Correct 322 ms 48344 KB Output is correct
70 Correct 294 ms 45092 KB Output is correct
71 Correct 409 ms 51052 KB Output is correct
72 Correct 261 ms 32980 KB Output is correct
73 Correct 248 ms 33212 KB Output is correct
74 Correct 400 ms 35296 KB Output is correct
75 Correct 607 ms 34900 KB Output is correct
76 Correct 723 ms 35412 KB Output is correct
77 Correct 612 ms 34356 KB Output is correct
78 Correct 650 ms 35004 KB Output is correct