提交记录 47680


用户 题目 状态 得分 用时 内存 语言 代码长度
jiegec noip18c. 【NOIP2018】赛道修建 Accepted 100 53.893 ms 8432 KB C++17 2.66 KB
提交时间 评测时间
2026-09-13 01:19:20 2026-09-13 01:19:26
// This code is AI-generated. (AI 生成的代码)
#pragma GCC optimize("O3")
#pragma GCC target("avx2,bmi2")
// NOIP2018 赛道修建: binary search the answer X.  Check(X): DFS; child chains
// reaching a node are either closed (length >= X) or paired with each other to
// reach X (greedy two-pointer); the largest unpaired chain is passed to parent.
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
enum { MAXN = 50005, MAXE = 100005 };
static int head[MAXN], nx_[MAXE], to_[MAXE], wt_[MAXE], ec;
static int X, formed;
static int pool[MAXN], sp;
static int nxtp[MAXN];
static char usedp[MAXN];
static int findn(int p, int end) {
    int r = p;
    while (r < end && usedp[r]) r = nxtp[r];
    while (p < r) { int t = nxtp[p]; nxtp[p] = r; p = t; }
    return r;
}
static void ae(int u, int v, int w) {
    to_[++ec] = v; wt_[ec] = w; nx_[ec] = head[u]; head[u] = ec;
}
static int dfs(int u, int fa) {
    int base = sp, k = 0;
    for (int e = head[u]; e; e = nx_[e]) {
        int v = to_[e];
        if (v == fa) continue;
        int d = dfs(v, u) + wt_[e];
        if (d >= X) formed++;
        else { pool[base + k] = d; k++; sp = base + k; }
    }
    sort(pool + base, pool + base + k);
    int end = base + k;
    for (int i = base; i <= end; i++) { nxtp[i] = i; usedp[i] = 0; }
    int ret = 0;
    for (int i = base; i < end; i++) {
        if (usedp[i]) continue;
        int pos = (int)(lower_bound(pool + i + 1, pool + end, X - pool[i]) - pool);
        pos = findn(pos, end);
        if (pos < end) {
            nxtp[i] = findn(i + 1, end);
            nxtp[pos] = findn(pos + 1, end);
            usedp[i] = usedp[pos] = 1;
            formed++;
        } else {
            ret = pool[i];
        }
    }
    sp = base;
    return ret;
}
static char ib[1 << 22], ob[32];
static char *gp;
static inline int rd() { while (*gp < '0') gp++; int v = 0; while (*gp >= '0' && *gp <= '9') v = v * 10 + (*gp++ - '0'); return v; }
int main() {
    int len = (int)fread(ib, 1, sizeof(ib) - 1, stdin);
    ib[len] = 0; gp = ib;
    int n = rd(), m = rd();
    long long total = 0;
    for (int i = 1; i < n; i++) {
        int a = rd(), b = rd(), w = rd();
        ae(a, b, w); ae(b, a, w); total += w;
    }
    int lo = 0, hi = (int)(total / m), ans = 0;
    while (lo <= hi) {
        int mid = (lo + hi) >> 1;
        X = mid; formed = 0;
        if (mid == 0) { ans = 0; lo = 1; continue; }
        dfs(1, 0);
        if (formed >= m) { ans = mid; lo = mid + 1; }
        else hi = mid - 1;
    }
    char *op = ob; int k = 0; char t[16];
    while (ans) { t[k++] = (char)('0' + ans % 10); ans /= 10; }
    while (k) *op++ = t[--k];
    *op++ = '\n';
    fwrite(ob, 1, op - ob, stdout);
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #110.7 us48 KBAcceptedScore: 5

Testcase #211.61 us48 KBAcceptedScore: 5

Testcase #312.89 us48 KBAcceptedScore: 5

Testcase #4551.15 us100 KBAcceptedScore: 5

Testcase #553.893 ms1 MB + 456 KBAcceptedScore: 5

Testcase #645.011 ms1 MB + 792 KBAcceptedScore: 5

Testcase #733.897 ms1 MB + 464 KBAcceptedScore: 5

Testcase #851.544 ms2 MB + 392 KBAcceptedScore: 5

Testcase #9325.59 us212 KBAcceptedScore: 5

Testcase #1015.767 ms4 MB + 980 KBAcceptedScore: 5

Testcase #1131.202 ms8 MB + 240 KBAcceptedScore: 5

Testcase #1225.77 us48 KBAcceptedScore: 5

Testcase #1323.2 us48 KBAcceptedScore: 5

Testcase #1471.11 us52 KBAcceptedScore: 5

Testcase #1568.17 us60 KBAcceptedScore: 5

Testcase #16357.5 us112 KBAcceptedScore: 5

Testcase #17411.15 us96 KBAcceptedScore: 5

Testcase #1823.553 ms1 MB + 328 KBAcceptedScore: 5

Testcase #1925.194 ms1 MB + 768 KBAcceptedScore: 5

Testcase #2044.07 ms2 MB + 992 KBAcceptedScore: 5


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