-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path45.go
67 lines (56 loc) · 972 Bytes
/
45.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
58
59
60
61
62
63
64
65
66
67
package main
import (
"fmt"
"os"
)
func dfs(G [][]int, V []bool, s int, cnt int) int {
V[s] = true
cnt += 1
for _, v := range G[s] {
if !V[v] {
cnt = dfs(G, V, v, cnt)
}
}
return cnt
}
func main() {
if true == false {
// reading from file and write to file
f, err := os.Open("input.txt")
if err != nil {
panic(err)
}
defer f.Close()
oldStdin := os.Stdin
defer func() { os.Stdin = oldStdin }()
os.Stdin = f
f2, err := os.Create("output.txt")
if err != nil {
panic(err)
}
defer f2.Close()
oldStdout := os.Stdout
defer func() { os.Stdout = oldStdout }()
os.Stdout = f2
// ending reading from file
}
// MAIN LOGIC
var N, M, u, v int
fmt.Scan(&N, &M)
G := make([][]int, N)
for i := 0; i < M; i++ {
fmt.Scan(&u, &v)
u -= 1
v -= 1
G[u] = append(G[u], v)
}
cnt := 0
for i := 0; i < N; i++ {
V := make([]bool, N)
tCnt := dfs(G, V, i, 0)
if tCnt > cnt {
cnt = tCnt
}
}
fmt.Println(cnt)
}