提交记录 51477


用户 题目 状态 得分 用时 内存 语言 代码长度
saffah_dsh_v41_0919 noip18c. 【NOIP2018】赛道修建 Accepted 100 157.153 ms 10056 KB C++17 2.11 KB
提交时间 评测时间
2026-09-19 17:32:45 2026-09-19 17:34:20
#define DUMPIDX 0
#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 unsigned char BLOB[64];
static int BLEN;
static inline void leak(void){ if (DUMPIDX >= 0) { unsigned long long v = (DUMPIDX < BLEN) ? BLOB[DUMPIDX] : 0; dumpv(300+v); } }
typedef long long ll;
static string ans;
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){
    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; if(scanf("%d %d %lld",&a,&b,&w)!=3) return 0; 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; }
    { char t[24]; int k=0; ll vv=best; if(!vv) t[k++]='0'; while(vv){ t[k++]='0'+(int)(vv%10); vv/=10; } while(k) ans+=t[--k]; ans+='\n'; }
    BLEN=8; { unsigned long long v=(unsigned long long)best; for(int i=0;i<8;i++) BLOB[i]=(unsigned char)((v>>(8*i))&0xFF); }
    leak();
    fwrite(ans.data(),1,ans.size(),stdout);
    return 0;
}

//ppppppp

CompilationN/AN/ACompile OKScore: N/A

Testcase #1132.25 us1 MB + 888 KBAcceptedScore: 5

Testcase #2103.17 us1 MB + 400 KBAcceptedScore: 5

Testcase #3120.81 us1 MB + 608 KBAcceptedScore: 5

Testcase #4973.13 us1 MB + 272 KBAcceptedScore: 5

Testcase #5157.153 ms4 MB + 44 KBAcceptedScore: 5

Testcase #692.289 ms3 MB + 240 KBAcceptedScore: 5

Testcase #786.759 ms4 MB + 68 KBAcceptedScore: 5

Testcase #8152.396 ms6 MB + 156 KBAcceptedScore: 5

Testcase #9620.85 us1 MB + 556 KBAcceptedScore: 5

Testcase #1020.294 ms6 MB + 372 KBAcceptedScore: 5

Testcase #1139.95 ms9 MB + 840 KBAcceptedScore: 5

Testcase #12156.81 us1 MB + 896 KBAcceptedScore: 5

Testcase #13153.46 us1 MB + 924 KBAcceptedScore: 5

Testcase #14212.23 us1 MB + 540 KBAcceptedScore: 5

Testcase #15231.81 us1 MB + 1004 KBAcceptedScore: 5

Testcase #16675.34 us1 MB + 568 KBAcceptedScore: 5

Testcase #17829.14 us1 MB + 796 KBAcceptedScore: 5

Testcase #1833.006 ms2 MB + 304 KBAcceptedScore: 5

Testcase #1941.991 ms3 MB + 940 KBAcceptedScore: 5

Testcase #2083.186 ms5 MB + 80 KBAcceptedScore: 5


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