제출 #1352365

#제출 시각아이디문제언어결과실행 시간메모리
1352365vjudge1Parkovi (COCI22_parkovi)C++20
110 / 110
576 ms39868 KiB
#include<bits/stdc++.h>

#define hyc_qcz_jmr_baoyouwo_AC

#define int long long
#define made_by_ztyroy return 0;

#define rep(i,s,e) for(int i=s;i<=e;i++) 
#define fep(i,s,e) for(int i=s;i<e;i++) 
#define per(i,s,e) for(int i=s;i>=e;i--) 
#define pef(i,s,e) for(int i=s;i>e;i--)

namespace FastIO{
	template <typename T> inline void read(T &x){
		x=0;
		T f=1;
		T c=getchar();
		for(;!isdigit(c);c=getchar()){
			if(c=='-'){
				f=-1;
			}
		}
		for(;isdigit(c);c=getchar()){
			x=(x<<1)+(x<<3)+(c^48);
		}
		x*=f;
	}
	template <typename T,typename... Args> inline void read(T &x,Args &...args){
		read(x);
		read(args...);
	}
	template <typename T> inline void print(T x){
		if(x<0){
			putchar('-');
			x=-x;
		}
		if(x>9){
			print(x/10);
		}
		putchar((x%10)^48);
	}
	template <typename T,typename... Args> inline void print(T x,Args ...args){
		print(x);
		putchar('\n');
		print(args...);
	}
}

using namespace std;
using namespace FastIO;
struct node{
	int hav;
	vector<pair<int,int> >son;
}p[200005];
int n,m,num,u,v,w; 
namespace big{
	int ans,cnt,dp[2][200005],chos[200005];
	void dfs(int now,int fa,int thi){
		chos[now]=0;
		dp[0][now]=-0x3f3f3f3f3f3f3f3f;
		dp[1][now]=0x3f3f3f3f3f3f3f3f;
		for(auto i:p[now].son){
			if(i.first==fa){
				continue;
			}
			dfs(i.first,now,thi);
			if(dp[0][i.first]+i.second>thi){
				chos[i.first]=1;
				dp[0][i.first]=-0x3f3f3f3f3f3f3f3f;
				dp[1][i.first]=0;
				++cnt;
			}
			dp[1][now]=min(dp[1][now],dp[1][i.first]+i.second);
		}
		if(dp[1][now]>thi){
			dp[0][now]=max(dp[0][now],0ll);
		}
		for(auto i:p[now].son){
			if(i.first==fa){
				continue;
			}
			if(dp[1][now]+dp[0][i.first]+i.second>thi){
				dp[0][now]=max(dp[0][now],dp[0][i.first]+i.second);
			}
		}
	}
	bool check(int now){
		cnt=0;
		dfs(1,0,now);
		if(dp[0][1]>=0){
			++cnt;
		}
		return cnt<=m;
	}
	void solve(){
		int l=0,r=2e14;
		while(l<=r){
			int mid=((l+r)>>1);
			if(check(mid)==1){
				ans=mid;
				rep(i,1,n){
					p[i].hav=chos[i];
				}
				r=mid-1;
			}
			else{
				l=mid+1;
			}
		} 
		print(ans);
		putchar('\n');
		cnt=0;
		rep(i,1,n){
			if(p[i].hav==1){
				++cnt;
				print(i);
				putchar(' ');
			}
		}
		for(int i=1;i<=n&&cnt<m;i++){
			if(p[i].hav==0){
				++cnt;
				print(i);
				putchar(' ');
			}
		}
	}
}
signed main(){
	hyc_qcz_jmr_baoyouwo_AC
	read(n,m);
	fep(i,1,n){
		read(u,v,w);
		p[u].son.emplace_back(v,w);
		p[v].son.emplace_back(u,w);
	}
	big::solve();
	made_by_ztyroy
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...