唐诗错误|如果你 only AC on #12
查看原帖
唐诗错误|如果你 only AC on #12
1313895
CLydq楼主2024/12/18 14:47

数据:

6
0 1 59
0 2 63
2 3 65
0 4 6
3 5 46
2
C 2 2
MAX 3 4

ANS:

65

WA OUT:

63

如果你和我一样,把边权赋给了儿子(强制某个点为根,我的根是 1 号点):

void dfs1(int u, int fa) {
    dep[u] = dep[fa] + 1, ::fa[u] = fa, sz[u] = 1;
    for (edge ed : g[u])
        if (ed.v != fa) {
            dfs1(ed.v, u);
            sz[u] += sz[ed.v], to[ed.id] = ed.v;
            if (sz[ed.v] > sz[hs[u]])
                hsw[u] = ed.w, hs[u] = ed.v;
        }
}
void dfs2(int u, int top, int w) {
    id[u] = ++cnt, ::top[u] = top, a[cnt] = w;
    if (!hs[u])
        return;
    dfs2(hs[u], top, hsw[u]);
    for (edge ed : g[u])
        if (ed.v != fa[u] && ed.v != hs[u])
            dfs2(ed.v, ed.v, ed.w);
}

其中,to 数组是下标为 i 的边边权被赋给了哪个点。

然后你操作 C 是这么处理的:scanf("%d%d", &u, &w), update(1, id[to[u]], id[to[u]], w, 0);

最后的 0 参数表示这是操作 C

确认一下你的 to 数组中存放的编号是一开始的时候点的编号还是 dfs 序。

因为线段树 update 下标是 dfs 序,所以我这里写 update(1, to[u], to[u], w, 0) 就会 WA 掉。

WA

AC

2024/12/18 14:47
加载中...