提交记录 10002


用户 题目 状态 得分 用时 内存 语言 代码长度
Frozencode noip18c. 【NOIP2018】赛道修建 Accepted 100 429.637 ms 13460 KB C++11 1.51 KB
提交时间 评测时间
2019-08-05 19:58:26 2020-08-01 02:00:22
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll maxn=500010;
const ll INF=2147483647;
struct edge{
	ll to,val;
}e[maxn];
ll n,m,head[maxn],nxt[maxn],tot,x,y,z,l,r,ans[maxn],len[maxn],fa[maxn],cnt;
bool vis[maxn];
multiset<ll>s;

multiset<ll>::iterator it;
void add_edge(ll x,ll y,ll z){
	nxt[++tot] = head[x];
	e[tot].to = y;
	e[tot].val = z;
	head[x] = tot;
}
void dfs(ll x,ll sum){
	vis[x] = 1;
	for(int i = head[x]; i;i = nxt[i]){
		ll tem = e[i].to;
		if(!vis[tem]){
			fa[tem] = x;
			dfs(tem,sum);
		}
	}
	s.clear();
	for(int i = head[x]; i;i = nxt[i]){
		ll tem = e[i].to;
		if(fa[tem] != x)continue;
		if(e[i].val + len[tem] >= sum)ans[x]++;
		else s.insert(e[i].val + len[tem]);
	}
	ll maxx = 0;
	while(!s.empty()){
		if(s.size() == 1){
			maxx = max(maxx,*s.begin());

			break;

		}
		it = s.lower_bound(sum - *s.begin());

		if(it == s.begin() && s.count(*it) == 1)it++;
		if(it == s.end()){
			maxx = max(maxx,*s.begin());

			s.erase(s.find(*s.begin()));

		}
		else{
			ans[x]++;
			s.erase(s.find(*it));
			s.erase(s.find(*s.begin()));

		}
	}
	len[x] = maxx;
	cnt += ans[x];
	return;
}
bool check(ll x){
	cnt = 0;
	memset(vis,0,sizeof(vis));
	memset(ans,0,sizeof(ans));
	dfs(1,x);
	return (cnt >= m) ? true : false;
}
int main()
{

	ios::sync_with_stdio(false);

	cin>>n>>m;
	for(int i = 1;i < n;i++){
		cin>>x>>y>>z;
		add_edge(x,y,z);

		add_edge(y,x,z);

	}
	l = 1;
	r = INF;
	while(l < r - 1){
		ll mid = (l + r)>>1;
		if(check(mid)){
			l = mid;
		}
		else r = mid;
	}
	cout<<l;
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #13.13 ms4 MB + 380 KBAcceptedScore: 5

Testcase #23.146 ms4 MB + 380 KBAcceptedScore: 5

Testcase #33.158 ms4 MB + 380 KBAcceptedScore: 5

Testcase #44.548 ms4 MB + 464 KBAcceptedScore: 5

Testcase #5233.717 ms7 MB + 828 KBAcceptedScore: 5

Testcase #6132.062 ms7 MB + 336 KBAcceptedScore: 5

Testcase #7238.025 ms7 MB + 828 KBAcceptedScore: 5

Testcase #8429.637 ms10 MB + 96 KBAcceptedScore: 5

Testcase #94.186 ms4 MB + 560 KBAcceptedScore: 5

Testcase #1064.705 ms9 MB + 652 KBAcceptedScore: 5

Testcase #11109.577 ms13 MB + 148 KBAcceptedScore: 5

Testcase #123.188 ms4 MB + 380 KBAcceptedScore: 5

Testcase #133.181 ms4 MB + 380 KBAcceptedScore: 5

Testcase #143.358 ms4 MB + 392 KBAcceptedScore: 5

Testcase #153.358 ms4 MB + 396 KBAcceptedScore: 5

Testcase #164.584 ms4 MB + 472 KBAcceptedScore: 5

Testcase #175.041 ms4 MB + 464 KBAcceptedScore: 5

Testcase #1888.604 ms6 MB + 500 KBAcceptedScore: 5

Testcase #19130.784 ms7 MB + 324 KBAcceptedScore: 5

Testcase #20221.666 ms9 MB + 168 KBAcceptedScore: 5


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