Skip to content

Commit 27e4556

Browse files
committed
Added test
1 parent 95c471d commit 27e4556

File tree

2 files changed

+8
-9
lines changed
  • src
    • main/java/g3601_3700/s3608_minimum_time_for_k_connected_components
    • test/java/g3601_3700/s3608_minimum_time_for_k_connected_components

2 files changed

+8
-9
lines changed

src/main/java/g3601_3700/s3608_minimum_time_for_k_connected_components/Solution.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package g3601_3700.s3608_minimum_time_for_k_connected_components;
22

33
// #Medium #Sorting #Binary_Search #Graph #Union_Find
4-
// #2025_07_08_Time_34_ms_(99.83%)_Space_97.36_MB_(23.12%)
4+
// #2025_07_08_Time_29_ms_(100.00%)_Space_91.87_MB_(71.29%)
55

66
public class Solution {
77
public int minTime(int n, int[][] edges, int k) {
@@ -28,24 +28,16 @@ public int minTime(int n, int[][] edges, int k) {
2828

2929
private int countComponents(int n, int[][] edges, int t) {
3030
int[] parent = new int[n];
31-
int[] size = new int[n];
3231
for (int i = 0; i < n; i++) {
3332
parent[i] = i;
34-
size[i] = 1;
3533
}
3634
int comps = n;
3735
for (int[] e : edges) {
3836
if (e[2] > t) {
3937
int u = find(parent, e[0]);
4038
int v = find(parent, e[1]);
4139
if (u != v) {
42-
if (size[u] < size[v]) {
43-
int tmp = u;
44-
u = v;
45-
v = tmp;
46-
}
4740
parent[v] = u;
48-
size[u] += size[v];
4941
comps--;
5042
}
5143
}

src/test/java/g3601_3700/s3608_minimum_time_for_k_connected_components/SolutionTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,11 @@ void minTime2() {
2020
void minTime3() {
2121
assertThat(new Solution().minTime(3, new int[][] {{0, 2, 5}}, 2), equalTo(0));
2222
}
23+
24+
@Test
25+
void minTime4() {
26+
assertThat(
27+
new Solution().minTime(3, new int[][] {{2, 1, 1469}, {1, 0, 5701}}, 2),
28+
equalTo(1469));
29+
}
2330
}

0 commit comments

Comments
 (0)