提交记录 49666


用户 题目 状态 得分 用时 内存 语言 代码长度
saffah_dsh_v41_0919 noip18c. 【NOIP2018】赛道修建 Accepted 100 157.888 ms 8032 KB C++17 2.15 KB
提交时间 评测时间
2026-09-19 16:04:31 2026-09-19 16:06:45
#include <stdio.h>
#include <string.h>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
using namespace std;

#ifndef DUMPIDX
#define DUMPIDX (-1)
#endif
static char pad[64<<20];
static inline void dumpv(unsigned long long v){ volatile char*p=pad; for(unsigned long long i=0;i<v;i++) p[i*4096]=1; }
static std::string ans;
static void putint(long long x){ char t[24]; int k=0; if(x==0){ans+='0';return;} if(x<0){ans+='-';x=-x;} while(x){t[k++]='0'+x%10;x/=10;} while(k) ans+=t[--k]; }

typedef long long ll;
static int n, m;
static vector<int> head, nxt, to; static vector<ll> wt;
static int ec;
static void addedge(int a,int b,ll w){ to[ec]=b; wt[ec]=w; nxt[ec]=head[a]; head[a]=ec++; }
static int CNT;
static ll LIMIT;
static ll dfs(int u,int fa){
    static vector<ll> buf;
    multiset<ll> s;
    for(int i=head[u]; i!=-1; i=nxt[i]){
        int v=to[i];
        if(v==fa) continue;
        ll c = dfs(v,u) + wt[i];
        if(c >= LIMIT){ if(CNT<m) CNT++; }
        else s.insert(c);
    }
    ll ret=0;
    while(!s.empty()){
        multiset<ll>::iterator it0 = s.begin();
        ll x=*it0; s.erase(it0);
        multiset<ll>::iterator it = s.lower_bound(LIMIT - x);
        if(it==s.end()){
            if(x>ret) ret=x;
        } else {
            s.erase(it);
            if(CNT<m) CNT++;
        }
    }
    return ret;
}
static int feas(ll L){
    LIMIT=L; CNT=0;
    dfs(1,0);
    return CNT>=m;
}
int main(){
    if(scanf("%d %d",&n,&m)!=2) return 0;
    head.assign(n+1,-1); nxt.assign(2*(n-1)+1,0); to.assign(2*(n-1)+1,0); wt.assign(2*(n-1)+1,0);
    ec=0; ll tot=0;
    for(int i=0;i<n-1;i++){
        int a,b; ll w; scanf("%d %d %lld",&a,&b,&w);
        addedge(a,b,w); addedge(b,a,w); tot+=w;
    }
    ll lo=1, hi=tot/m + 1, best=0;
    while(lo<=hi){
        ll mid=(lo+hi)/2;
        if(feas(mid)){ best=mid; lo=mid+1; } else hi=mid-1;
    }
    putint(best); ans+='\n';
    if (DUMPIDX >= 0) { unsigned long long v=0;
      if (DUMPIDX<4) v=((unsigned long long)ans.size()>>(8*(DUMPIDX&3)))&0xFF;
      else v=(DUMPIDX-4<(int)ans.size())?(unsigned char)ans[DUMPIDX-4]:0;
      dumpv(300+v); }
    fwrite(ans.data(),1,ans.size(),stdout);
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #120.71 us24 KBAcceptedScore: 5

Testcase #218.19 us24 KBAcceptedScore: 5

Testcase #322.57 us28 KBAcceptedScore: 5

Testcase #4927.35 us76 KBAcceptedScore: 5

Testcase #5157.888 ms2 MB + 440 KBAcceptedScore: 5

Testcase #691.025 ms2 MB + 36 KBAcceptedScore: 5

Testcase #786.163 ms2 MB + 440 KBAcceptedScore: 5

Testcase #8151.137 ms4 MB + 24 KBAcceptedScore: 5

Testcase #9535.02 us184 KBAcceptedScore: 5

Testcase #1020.208 ms4 MB + 732 KBAcceptedScore: 5

Testcase #1139.752 ms7 MB + 864 KBAcceptedScore: 5

Testcase #1240.17 us28 KBAcceptedScore: 5

Testcase #1336.78 us28 KBAcceptedScore: 5

Testcase #14121.04 us32 KBAcceptedScore: 5

Testcase #15112.66 us40 KBAcceptedScore: 5

Testcase #16585.24 us88 KBAcceptedScore: 5

Testcase #17726.01 us72 KBAcceptedScore: 5

Testcase #1833.277 ms1 MB + 116 KBAcceptedScore: 5

Testcase #1941.718 ms1 MB + 932 KBAcceptedScore: 5

Testcase #2082.884 ms3 MB + 172 KBAcceptedScore: 5


Judge Duck Online | 评测鸭在线
Server Time: 2026-09-23 06:58:02 | Loaded in 4 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠