Created
May 6, 2018 04:15
-
-
Save cipepser/2074c137813651c9fa039d281d654938 to your computer and use it in GitHub Desktop.
dfsでcycle detectしようとしたやつのメモ書き
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package undirected | |
type Graph struct { | |
n, m int | |
head, next []int | |
src, dst []int | |
} | |
func NewGraph(n int) *Graph { | |
h := make([]int, n) | |
for i := range h { | |
h[i] = -1 | |
} | |
g := &Graph{ | |
n: n, | |
m: 0, | |
head: h, | |
next: make([]int, n), | |
src: []int{}, | |
dst: []int{}, | |
} | |
return g | |
} | |
func (g *Graph) AddEdge(u, v int) { | |
g.next = append(g.next, g.head[u]) | |
g.head[u] = g.m | |
g.src = append(g.src, u) | |
g.dst = append(g.dst, v) | |
g.m++ | |
} | |
func (g *Graph) ExistsCycleByDFS() bool { | |
return false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment