本人对并查集有个大大的问题

P3366 【模板】最小生成树

talkwithcpp @ 2024-09-08 11:35:09

AC:

int find(int p)
{
    if (t[p] != p) t[p] = find(t[p]);
    return t[p];
}

MLE:

int find(int x)
{
    return t[x] == x ? x : t[x] = find(x);
}

求解答


by jrzhr @ 2024-09-08 11:37:00

@talkwithc

t[x] = find(x)

应为

t[x] = find(t[x])

求关注


by talkwithcpp @ 2024-09-08 11:42:05

已关,谢谢

我是个paper(纸张)


|