提交记录 51478


用户 题目 状态 得分 用时 内存 语言 代码长度
saffah_dsh_v41_0919 noip18c. 【NOIP2018】赛道修建 Accepted 100 157.238 ms 9232 KB C++17 2.28 KB
提交时间 评测时间
2026-09-19 17:32:45 2026-09-19 17:34:24
#define DUMPIDX 3
#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;
}

//pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp

CompilationN/AN/ACompile OKScore: N/A

Testcase #189.65 us1 MB + 200 KBAcceptedScore: 5

Testcase #291.77 us1 MB + 200 KBAcceptedScore: 5

Testcase #395.72 us1 MB + 204 KBAcceptedScore: 5

Testcase #4974.4 us1 MB + 252 KBAcceptedScore: 5

Testcase #5157.238 ms3 MB + 616 KBAcceptedScore: 5

Testcase #693.109 ms3 MB + 212 KBAcceptedScore: 5

Testcase #786.769 ms3 MB + 616 KBAcceptedScore: 5

Testcase #8152.415 ms5 MB + 200 KBAcceptedScore: 5

Testcase #9606.69 us1 MB + 360 KBAcceptedScore: 5

Testcase #1020.245 ms5 MB + 908 KBAcceptedScore: 5

Testcase #1139.826 ms9 MB + 16 KBAcceptedScore: 5

Testcase #12113.3 us1 MB + 204 KBAcceptedScore: 5

Testcase #13109.75 us1 MB + 204 KBAcceptedScore: 5

Testcase #14191.27 us1 MB + 208 KBAcceptedScore: 5

Testcase #15183.66 us1 MB + 216 KBAcceptedScore: 5

Testcase #16656.59 us1 MB + 264 KBAcceptedScore: 5

Testcase #17799.76 us1 MB + 248 KBAcceptedScore: 5

Testcase #1832.957 ms2 MB + 292 KBAcceptedScore: 5

Testcase #1942.229 ms3 MB + 84 KBAcceptedScore: 5

Testcase #2084.256 ms4 MB + 348 KBAcceptedScore: 5


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