求助
查看原帖
求助
498612
Saka_Noa楼主2023/8/14 13:28
int check(long long x)
{
    int i, j, cot = 0;
    ans = 0, tot = 0;
    For(i, 1, n) fa[i] = i;
    for (i = 1, j = 1; i <= cnt1 && j <= cnt2;)
    {

        if (e2[j].w + x <= e1[i].w)
        {
            int fx = find(e2[j].u), fy = find(e2[j].v);
            if (fx != fy)
                fa[fx] = fy, ans += e2[j].w, cot++, step[++tot] = e2[j].id;
            j++;
        }
        else

        {
            int fx = find(e1[i].u), fy = find(e1[i].v);
            if (fx != fy)
                fa[fx] = fy, ans += e1[i].w, step[++tot] = e1[i].id;
            i++;
        }
    }
    while (j <= cnt2)
    {
        int fx = find(e2[j].u), fy = find(e2[j].v);
        if (fx != fy)
            fa[fx] = fy, ans += e2[j].w, cot++, step[++tot] = e2[j].id;
        j++;
    }
    while (i <= cnt1)
    {
        int fx = find(e1[i].u), fy = find(e1[i].v);
        if (fx != fy)
            fa[fx] = fy, ans += e1[i].w, step[++tot] = e1[i].id;
        i++;
    }
    return cot;
}

checkcheck 函数这么写会不会有问题
e2e2 连向11的边
e1e1 其余的边

2023/8/14 13:28
加载中...