-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path10608.go
51 lines (45 loc) · 826 Bytes
/
10608.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// UVa 10608 - Friends
package main
import (
"fmt"
"os"
)
func unionFind(x int, f []int) int {
if f[x] != x {
f[x] = unionFind(f[x], f)
}
return f[x]
}
func max(f []int) int {
var m int
rootMap := make(map[int]int)
for i := range f {
root := unionFind(i, f)
rootMap[root]++
if rootMap[root] > m {
m = rootMap[root]
}
}
return m
}
func main() {
in, _ := os.Open("10608.in")
defer in.Close()
out, _ := os.Create("10608.out")
defer out.Close()
var kase, n, m, m1, m2 int
for fmt.Fscanf(in, "%d", &kase); kase > 0; kase-- {
fmt.Fscanf(in, "%d%d", &n, &m)
f := make([]int, n+1)
for i := range f {
f[i] = i
}
for ; m > 0; m-- {
fmt.Fscanf(in, "%d%d", &m1, &m2)
if f1, f2 := unionFind(m1, f), unionFind(m2, f); f1 != f2 {
f[f1] = f2
}
}
fmt.Fprintln(out, max(f))
}
}