blob: d7b025f1f651056ba57fc5b11826a2cb42d34e80 (
plain) (
blame)
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
|
package main
import "fmt"
func validPath(n int, edges [][]int, source int, destination int) bool {
seen := make([][]int, n)
for _, edge := range edges {
seen[edge[0]] = append(seen[edge[0]], edge[1])
seen[edge[1]] = append(seen[edge[1]], edge[0])
}
visited := map[int]struct{}{}
none := struct{}{}
q := []int{source}
for len(q) > 0 {
sz := len(q)
for i := 0; i < sz; i++ {
item := q[0]
if item == destination {
return true
}
if _, ok := visited[item]; !ok {
q = append(q, seen[item]...)
visited[item] = none
}
}
q = q[1:]
}
return false
}
func main() {
fmt.Println("vim-go")
}
|