-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path10926.go
57 lines (50 loc) · 800 Bytes
/
10926.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
52
53
54
55
56
57
// UVa 10926 - How Many Dependencies?
package main
import (
"fmt"
"os"
)
var (
count int
matrix [][]bool
)
func dfs(curr int) {
for i, cell := range matrix[curr] {
if cell {
count++
dfs(i)
}
}
}
func solve() int {
idx, max := -1, 0
for i := range matrix {
count = 0
if dfs(i); count > max {
idx = i
max = count
}
}
return idx + 1
}
func main() {
in, _ := os.Open("10926.in")
defer in.Close()
out, _ := os.Create("10926.out")
defer out.Close()
var n, d, dep int
for {
if fmt.Fscanf(in, "%d", &n); n == 0 {
break
}
matrix = make([][]bool, n)
for i := range matrix {
matrix[i] = make([]bool, n)
for fmt.Fscanf(in, "%d", &d); d > 0; d-- {
fmt.Fscanf(in, "%d", &dep)
matrix[i][dep-1] = true
}
}
fmt.Fprintln(out, solve())
}
}