提交记录 51445


用户 题目 状态 得分 用时 内存 语言 代码长度
saffah_dsh_v41_0919 noip18c. 【NOIP2018】赛道修建 Accepted 100 155.697 ms 8032 KB C++17 2.09 KB
提交时间 评测时间
2026-09-19 17:30:22 2026-09-19 17:32:41
#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 #120.5 us24 KBAcceptedScore: 5

Testcase #218.46 us24 KBAcceptedScore: 5

Testcase #323.04 us28 KBAcceptedScore: 5

Testcase #4901.4 us76 KBAcceptedScore: 5

Testcase #5155.697 ms2 MB + 440 KBAcceptedScore: 5

Testcase #689.482 ms2 MB + 36 KBAcceptedScore: 5

Testcase #786.335 ms2 MB + 440 KBAcceptedScore: 5

Testcase #8151.182 ms4 MB + 24 KBAcceptedScore: 5

Testcase #9544.88 us184 KBAcceptedScore: 5

Testcase #1020.327 ms4 MB + 732 KBAcceptedScore: 5

Testcase #1140.281 ms7 MB + 864 KBAcceptedScore: 5

Testcase #1239.81 us28 KBAcceptedScore: 5

Testcase #1336.77 us28 KBAcceptedScore: 5

Testcase #14116.9 us32 KBAcceptedScore: 5

Testcase #15109.12 us40 KBAcceptedScore: 5

Testcase #16584.6 us88 KBAcceptedScore: 5

Testcase #17728.46 us72 KBAcceptedScore: 5

Testcase #1833.354 ms1 MB + 116 KBAcceptedScore: 5

Testcase #1941.951 ms1 MB + 932 KBAcceptedScore: 5

Testcase #2085.479 ms3 MB + 172 KBAcceptedScore: 5


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