Skip to content

Commit 501e85f

Browse files
authored
Update DSU.h
1 parent dfc1440 commit 501e85f

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

DataStructures/DSU/DSU.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class DSU
99
DSU(int n)
1010
{
1111
parent = vector<int>(n);
12-
size = vector<int>(n);
12+
size = vector<int>(n, 1);
1313
iota(begin(parent), end(parent), 0);
1414
}
1515

@@ -25,6 +25,7 @@ class DSU
2525
y = getParent(y);
2626
if (size[x] > size[y])
2727
swap(x, y);
28+
if (x == y) return;
2829
parent[x] = y;
2930
size[y] += size[x];
3031
}

0 commit comments

Comments
 (0)