提交记录 9965


用户 题目 状态 得分 用时 内存 语言 代码长度
Wallbreaker5th noip18c. 【NOIP2018】赛道修建 Accepted 100 169.575 ms 8440 KB C++ 1.41 KB
提交时间 评测时间
2019-07-31 17:11:02 2020-08-01 01:59:47
#include<bits/stdc++.h>
using namespace std;
inline int getint(){
	int ans=0;
	char c=getchar();
	while(c<'0'||c>'9'){
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		ans=ans*10+c-'0';
		c=getchar();
	}
	return ans;
}
const int N=100010,M=N<<1;

struct bian{
	int l,e,n;
};
bian b[M];
int s[N],tot=0;
inline void add(int x,int y,int z){
	tot++;
	b[tot].l=z;
	b[tot].e=y;
	b[tot].n=s[x];
	s[x]=tot;
}

long long maxson[N];
int cnt=0,mid=0;
void ss(int x,int fa){
	//cout<<">>>"<<x<<endl;
	for(int i=s[x];i;i=b[i].n){
		if(b[i].e==fa)continue;
		ss(b[i].e,x);
	}
	multiset<long long> sons;
	for(int i=s[x];i;i=b[i].n){
		if(b[i].e==fa)continue;
		sons.insert(maxson[b[i].e]+b[i].l);
	}
	multiset<long long>::reverse_iterator it=sons.rbegin();
	while(sons.size()){
		if(*it>=mid){
			cnt++;
			sons.erase(sons.find(*it));
		}else break;
	}
	while(sons.size()){
		int t=*sons.begin();
		sons.erase(sons.begin());
		multiset<long long>::iterator itt=sons.lower_bound(mid-t);
		if(itt==sons.end())maxson[x]=t;
		else cnt++,sons.erase(itt);
	}
	//cout<<">> "<<x<<" "<<maxson[x]<<endl;
}
int main(){
	int n=getint(),m=getint();
	long long sum=0;
	for(int i=0;i<n-1;i++){
		int x=getint(),y=getint(),z=getint();
		add(x,y,z);
		add(y,x,z);
		sum+=z;
	}
	long long l=0,r=sum/m+1;
	while(l<r){
		mid=(l+r+1)>>1;
		cnt=0;
		memset(maxson,0,sizeof(maxson));
		ss(2,0);
		if(cnt>=m)l=mid;
		else r=mid-1;
		//cout<<"---"<<mid<<"---"<<endl;
	}
	cout<<l;
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #1329.91 us824 KBAcceptedScore: 5

Testcase #2305.37 us824 KBAcceptedScore: 5

Testcase #3311.19 us824 KBAcceptedScore: 5

Testcase #41.392 ms864 KBAcceptedScore: 5

Testcase #5169.575 ms2 MB + 1004 KBAcceptedScore: 5

Testcase #699.244 ms2 MB + 620 KBAcceptedScore: 5

Testcase #792.979 ms2 MB + 1004 KBAcceptedScore: 5

Testcase #8167.935 ms4 MB + 440 KBAcceptedScore: 5

Testcase #9932.76 us976 KBAcceptedScore: 5

Testcase #1022.999 ms5 MB + 272 KBAcceptedScore: 5

Testcase #1141.782 ms8 MB + 248 KBAcceptedScore: 5

Testcase #12337.41 us824 KBAcceptedScore: 5

Testcase #13338.5 us824 KBAcceptedScore: 5

Testcase #14447.72 us828 KBAcceptedScore: 5

Testcase #15427.56 us836 KBAcceptedScore: 5

Testcase #16973.86 us868 KBAcceptedScore: 5

Testcase #171.165 ms868 KBAcceptedScore: 5

Testcase #1833.481 ms1 MB + 680 KBAcceptedScore: 5

Testcase #1949.014 ms2 MB + 548 KBAcceptedScore: 5

Testcase #2088.79 ms3 MB + 600 KBAcceptedScore: 5


Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 10:15:33 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠