func (g Undirected) Size() int {
	m2 := 0
	for fr, to := range g.AdjacencyList {
		m2 += len(to)
		for _, to := range to {
			if to == NI(fr) {
				m2++
			}
		}
	}
	return m2 / 2
}
Size returns the number of edges in g.

See also ArcSize and HasLoop.
package graph
func (g Undirected) Bipartite(n NI) (b bool, c1, c2 Bits, oc []NI) {
	b = true
	var open bool
	var df func(n NI, c1, c2 *Bits)
	df = func(n NI, c1, c2 *Bits) {
		c1.SetBit(n, 1)
		for _, nb := range g.AdjacencyList[n] {
			if c1.Bit(nb) == 1 {
				b = false
				oc = []NI{nb, n}
				open = true
				return
			}
			if c2.Bit(nb) == 1 {
				continue
			}
			df(nb, c2, c1)
			if b {
				continue
			}
			switch {
			case !open:
			case n == oc[0]:
				open = false
			default:
				oc = append(oc, n)
			}
			return
		}
	}
	df(n, &c1, &c2)
	if b {
		return b, c1, c2, nil
	}
	return b, Bits{}, Bits{}, oc
}
func (g Undirected) BronKerbosch1(emit func([]NI) bool) {
	a := g.AdjacencyList
	var f func(R, P, X *Bits) bool
	f = func(R, P, X *Bits) bool {
		switch {
		case !P.Zero():
			var r2, p2, x2 Bits
			pf := func(n NI) bool {
				r2.Set(*R)
				r2.SetBit(n, 1)
				p2.Clear()
				x2.Clear()
				for _, to := range a[n] {
					if P.Bit(to) == 1 {
						p2.SetBit(to, 1)
					}
					if X.Bit(to) == 1 {
						x2.SetBit(to, 1)
					}
				}
				if !f(&r2, &p2, &x2) {
					return false
				}
				P.SetBit(n, 0)
				X.SetBit(n, 1)
				return true
			}
			if !P.Iterate(pf) {
				return false
			}
		case X.Zero():
			return emit(R.Slice())
		}
		return true
	}
	var R, P, X Bits
	P.SetAll(len(a))
	f(&R, &P, &X)
}
func (g Undirected) BKPivotMaxDegree(P, X *Bits) (p NI) {
	a := g.AdjacencyList
	maxDeg := -1
	P.Iterate(func(n NI) bool {  
		if d := len(a[n]); d > maxDeg {
			p = n
			maxDeg = d
		}
		return true
	})
	X.Iterate(func(n NI) bool {  
		if d := len(a[n]); d > maxDeg {
			p = n
			maxDeg = d
		}
		return true
	})
	return
}
func (g Undirected) BKPivotMinP(P, X *Bits) NI {
	return P.From(0)
}
func (g Undirected) BronKerbosch2(pivot func(P, X *Bits) NI, emit func([]NI) bool) {
	a := g.AdjacencyList
	var f func(R, P, X *Bits) bool
	f = func(R, P, X *Bits) bool {
		switch {
		case !P.Zero():
			var r2, p2, x2, pnu Bits
			pnu.Set(*P)
			for _, to := range a[pivot(P, X)] {
				pnu.SetBit(to, 0)
			}
			pf := func(n NI) bool {
				r2.Set(*R)
				r2.SetBit(n, 1)
				p2.Clear()
				x2.Clear()
				for _, to := range a[n] {
					if P.Bit(to) == 1 {
						p2.SetBit(to, 1)
					}
					if X.Bit(to) == 1 {
						x2.SetBit(to, 1)
					}
				}
				if !f(&r2, &p2, &x2) {
					return false
				}
				P.SetBit(n, 0)
				X.SetBit(n, 1)
				return true
			}
			if !pnu.Iterate(pf) {
				return false
			}
		case X.Zero():
			return emit(R.Slice())
		}
		return true
	}
	var R, P, X Bits
	P.SetAll(len(a))
	f(&R, &P, &X)
}
func (g Undirected) BronKerbosch3(pivot func(P, X *Bits) NI, emit func([]NI) bool) {
	a := g.AdjacencyList
	var f func(R, P, X *Bits) bool
	f = func(R, P, X *Bits) bool {
		switch {
		case !P.Zero():
			var r2, p2, x2, pnu Bits
			pnu.Set(*P)
			for _, to := range a[pivot(P, X)] {
				pnu.SetBit(to, 0)
			}
			pf := func(n NI) bool {
				r2.Set(*R)
				r2.SetBit(n, 1)
				p2.Clear()
				x2.Clear()
				for _, to := range a[n] {
					if P.Bit(to) == 1 {
						p2.SetBit(to, 1)
					}
					if X.Bit(to) == 1 {
						x2.SetBit(to, 1)
					}
				}
				if !f(&r2, &p2, &x2) {
					return false
				}
				P.SetBit(n, 0)
				X.SetBit(n, 1)
				return true
			}
			if !pnu.Iterate(pf) {
				return false
			}
		case X.Zero():
			return emit(R.Slice())
		}
		return true
	}
	var R, P, X Bits
	P.SetAll(len(a))
	_, ord, _ := g.Degeneracy()
	var p2, x2 Bits
	for _, n := range ord {
		R.SetBit(n, 1)
		p2.Clear()
		x2.Clear()
		for _, to := range a[n] {
			if P.Bit(to) == 1 {
				p2.SetBit(to, 1)
			}
			if X.Bit(to) == 1 {
				x2.SetBit(to, 1)
			}
		}
		if !f(&R, &p2, &x2) {
			return
		}
		R.SetBit(n, 0)
		P.SetBit(n, 0)
		X.SetBit(n, 1)
	}
}
func (g Undirected) ConnectedComponentBits() func() (order int, bits Bits) {
	a := g.AdjacencyList
	var vg Bits   
	var vc *Bits  
	var nc int
	var df func(NI)
	df = func(n NI) {
		vg.SetBit(n, 1)
		vc.SetBit(n, 1)
		nc++
		for _, nb := range a[n] {
			if vg.Bit(nb) == 0 {
				df(nb)
			}
		}
		return
	}
	var n NI
	return func() (o int, bits Bits) {
		for ; n < NI(len(a)); n++ {
			if vg.Bit(n) == 0 {
				vc = &bits
				nc = 0
				df(n)
				return nc, bits
			}
		}
		return
	}
}
func (g Undirected) ConnectedComponentLists() func() []NI {
	a := g.AdjacencyList
	var vg Bits  
	var m []NI   
	var df func(NI)
	df = func(n NI) {
		vg.SetBit(n, 1)
		m = append(m, n)
		for _, nb := range a[n] {
			if vg.Bit(nb) == 0 {
				df(nb)
			}
		}
		return
	}
	var n NI
	return func() []NI {
		for ; n < NI(len(a)); n++ {
			if vg.Bit(n) == 0 {
				m = nil
				df(n)
				return m
			}
		}
		return nil
	}
}
func (g Undirected) ConnectedComponentReps() (reps []NI, orders []int) {
	a := g.AdjacencyList
	var c Bits
	var o int
	var df func(NI)
	df = func(n NI) {
		c.SetBit(n, 1)
		o++
		for _, nb := range a[n] {
			if c.Bit(nb) == 0 {
				df(nb)
			}
		}
		return
	}
	for n := range a {
		if c.Bit(NI(n)) == 0 {
			reps = append(reps, NI(n))
			o = 0
			df(NI(n))
			orders = append(orders, o)
		}
	}
	return
}
func (g Undirected) Copy() (c Undirected, ma int) {
	l, s := g.AdjacencyList.Copy()
	return Undirected{l}, s
}
func (g Undirected) Degeneracy() (k int, ordering []NI, cores []int) {
	a := g.AdjacencyList
	ordering = make([]NI, len(a))
	var L Bits
	d := make([]int, len(a))
	var D [][]NI
	for v, nb := range a {
		dv := len(nb)
		d[v] = dv
		for len(D) <= dv {
			D = append(D, nil)
		}
		D[dv] = append(D[dv], NI(v))
	}
	for ox := range a {
		i := 0
		for len(D[i]) == 0 {
			i++
		}
		if i > k {
			for len(cores) <= i {
				cores = append(cores, 0)
			}
			cores[k] = ox
			k = i
		}
		Di := D[i]
		last := len(Di) - 1
		v := Di[last]
		ordering[ox] = v
		L.SetBit(v, 1)
		D[i] = Di[:last]
		for _, nb := range a[v] {
			if L.Bit(nb) == 1 {
				continue
			}
			dn := d[nb]   
			Ddn := D[dn]  
			for wx, w := range Ddn {
				if w == nb {
					last := len(Ddn) - 1
					Ddn[wx], Ddn[last] = Ddn[last], Ddn[wx]
					D[dn] = Ddn[:last]
				}
			}
			dn--  
			d[nb] = dn
			D[dn] = append(D[dn], nb)
		}
	}
	cores[k] = len(ordering)
	return
}
func (g Undirected) Degree(n NI) int {
	to := g.AdjacencyList[n]
	d := len(to)  
	for _, to := range to {
		if to == n {
			d++  
		}
	}
	return d
}
func (g Undirected) FromList(root NI) (f FromList, cycle NI) {
	p := make([]PathEnd, len(g.AdjacencyList))
	for i := range p {
		p[i].From = -1
	}
	ml := 0
	var df func(NI, NI) bool
	df = func(fr, n NI) bool {
		l := p[n].Len + 1
		for _, to := range g.AdjacencyList[n] {
			if to == fr {
				continue
			}
			if p[to].Len > 0 {
				cycle = to
				return false
			}
			p[to] = PathEnd{From: n, Len: l}
			if l > ml {
				ml = l
			}
			if !df(n, to) {
				return false
			}
		}
		return true
	}
	p[root].Len = 1
	if !df(-1, root) {
		return
	}
	return FromList{Paths: p, MaxLen: ml}, -1
}
func (g Undirected) IsConnected() bool {
	a := g.AdjacencyList
	if len(a) == 0 {
		return true
	}
	var b Bits
	b.SetAll(len(a))
	var df func(NI)
	df = func(n NI) {
		b.SetBit(n, 0)
		for _, to := range a[n] {
			if b.Bit(to) == 1 {
				df(to)
			}
		}
	}
	df(0)
	return b.Zero()
}
func (g Undirected) IsTree(root NI) (isTree, allTree bool) {
	a := g.AdjacencyList
	var v Bits
	v.SetAll(len(a))
	var df func(NI, NI) bool
	df = func(fr, n NI) bool {
		if v.Bit(n) == 0 {
			return false
		}
		v.SetBit(n, 0)
		for _, to := range a[n] {
			if to != fr && !df(n, to) {
				return false
			}
		}
		return true
	}
	v.SetBit(root, 0)
	for _, to := range a[root] {
		if !df(root, to) {
			return false, false
		}
	}
	return true, v.Zero()
}