Skip to content

Instantly share code, notes, and snippets.

@cipepser
Created May 6, 2018 04:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cipepser/2074c137813651c9fa039d281d654938 to your computer and use it in GitHub Desktop.
Save cipepser/2074c137813651c9fa039d281d654938 to your computer and use it in GitHub Desktop.
dfsでcycle detectしようとしたやつのメモ書き
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