线段树合并解法6分可能原因

P3899 [湖南集训] 更为厉害

DoorKickers @ 2020-05-07 15:02:35

可能是在dfs的时候先合并后insert当前节点

会修改不应该修改的节点

新增节点式的合并也会宝玲.

举个例子

宝玲:

void dfs(int x, int fa, int dep)
{
    siz[x] = 1;
    deep[x] = dep;
    for (int i = head[x]; i; i = nex[i])
    {
        int y = ver[i];
        if (y == fa) continue;
        dfs(y, x, dep + 1);
        siz[x] += siz[y];
        rt[x] = merge(rt[x], rt[y]);
    }
    insert(rt[x], 1, n, dep, siz[x] - 1);
}

AC:

void dfs(int x, int fa)
{
    siz[x] = 1;
    for (int i = head[x]; i; i = nex[i])
    {
        int y = ver[i];
        if (y == fa) continue;
        dfs(y, x);
        siz[x] += siz[y];
    }
}

void dfs2(int x, int fa, int dep)
{
    insert(rt[x], 1, n, dep, siz[x] - 1);
    deep[x] = dep;
    for (int i = head[x]; i; i = nex[i])
    {
        int y = ver[i];
        if (y == fa) continue;
        dfs2(y, x, dep + 1);
        rt[x] = merge(rt[x], rt[y]);
    }
}

by tangrunxi @ 2020-05-07 15:04:56

%%%


by xhQYm @ 2020-05-07 15:09:38

orz


by JROI官方账号 @ 2020-05-07 15:12:11

这道题好像就是因为已死的小波说zzmg才被改名的(雾


by Semsue @ 2020-05-07 15:18:34

您说的这不是常识吗?


by Alan_Zhao @ 2020-05-07 15:26:43

宝玲可海星


by JRzyh @ 2020-05-07 15:34:56

@离散小波变换°

鞭尸


by DoorKickers @ 2020-05-07 21:06:26

@Flying_Bird 我太菜了dbq/kk


by DoorKickers @ 2020-05-07 21:08:03

话说为啥我基本上完全看不懂神奇网友的回复


|