请检查操作一的合并。
如果您是这样写的:
if (opt == 'M') {
cin >> x >> y;
if (tr[x] || tr[y] || x == y)continue;
x = find(x), y = find(y);
rt[x] = rt[y] = merge(x, y);
}
请改成:
if (opt == 'M') {
cin >> x >> y;
if (tr[x] || tr[y])continue;
x = find(x), y = find(y);
if (x != y)rt[x] = rt[y] = merge(x, y);
}
具体原因不明。