提交记录 8574


用户 题目 状态 得分 用时 内存 语言 代码长度
da32s1da noip18c. 【NOIP2018】赛道修建 Accepted 100 172.7 ms 8424 KB C++ 1.31 KB
提交时间 评测时间
2019-02-26 14:14:56 2020-08-01 01:21:31
#include<cstdio>
#include<set>
using namespace std;
const int N=5e4+50;
int fir[N],las[N<<1],to[N<<1],ds[N<<1],cnt;
inline void add_edge(int u,int v,int a){
    to[++cnt]=v;las[cnt]=fir[u];fir[u]=cnt;ds[cnt]=a;
    to[++cnt]=u;las[cnt]=fir[v];fir[v]=cnt;ds[cnt]=a;
}
inline int min(int u,int v){return u<v?u:v;}
inline int max(int u,int v){return u>v?u:v;}
int n,m,x,y,z,l,r,mid,Ans;
multiset<int>s[N];
typedef multiset<int>::iterator IT;
int dfs(int u,int v){
    int qwq=0,qvq=0;
    IT it;
    for(int i=fir[u];i;i=las[i])
    if(to[i]!=v){
        qvq=dfs(to[i],u)+ds[i];
        if(qvq>=mid)++Ans;
        else s[u].insert(qvq);
    }
    while(s[u].size()){
        qvq=*s[u].begin();
        s[u].erase(s[u].begin());
        it=s[u].lower_bound(mid-qvq);
        if(it!=s[u].end()){
            Ans++;
            s[u].erase(it);
        }else qwq=qvq;
    }
//	if(s[u].size()){
//		if(*s[u].begin()>=mid)Ans++;
//		else qwq=*s[u].begin();
//		s[u].clear();
//	}
    return qwq;
}
bool ok(){
    Ans=0;
    dfs(1,0);
    return Ans>=m;
}
int main(){
    scanf("%d%d",&n,&m);
    l=2e9;
    for(int i=1;i<n;i++){
        scanf("%d%d%d",&x,&y,&z);
        add_edge(x,y,z);
        l=min(l,z);
        r+=z;
    }
    r/=m;
    while(l<r){
        mid=l+r+1>>1;
        if(ok())l=mid;
        else r=mid-1;
    }
    printf("%d\n",l);
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #1404.45 us2 MB + 340 KBAcceptedScore: 5

Testcase #2413.87 us2 MB + 340 KBAcceptedScore: 5

Testcase #3412.48 us2 MB + 340 KBAcceptedScore: 5

Testcase #41.189 ms2 MB + 380 KBAcceptedScore: 5

Testcase #5172.7 ms4 MB + 520 KBAcceptedScore: 5

Testcase #690.824 ms4 MB + 28 KBAcceptedScore: 5

Testcase #786.805 ms4 MB + 520 KBAcceptedScore: 5

Testcase #8141.195 ms5 MB + 964 KBAcceptedScore: 5

Testcase #9868.5 us2 MB + 460 KBAcceptedScore: 5

Testcase #1018.754 ms5 MB + 900 KBAcceptedScore: 5

Testcase #1138.179 ms8 MB + 232 KBAcceptedScore: 5

Testcase #12432.89 us2 MB + 340 KBAcceptedScore: 5

Testcase #13429.22 us2 MB + 340 KBAcceptedScore: 5

Testcase #14493.54 us2 MB + 344 KBAcceptedScore: 5

Testcase #15490.6 us2 MB + 352 KBAcceptedScore: 5

Testcase #16916.68 us2 MB + 388 KBAcceptedScore: 5

Testcase #171.029 ms2 MB + 384 KBAcceptedScore: 5

Testcase #1832.652 ms3 MB + 192 KBAcceptedScore: 5

Testcase #1945.587 ms3 MB + 920 KBAcceptedScore: 5

Testcase #2077.782 ms4 MB + 928 KBAcceptedScore: 5


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