Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import "fmt"
- type Vertex struct {
- edges []int
- tin int
- fup int
- used bool
- }
- func filling_edge(m int, g []Vertex) {
- for i:=0; i < m; i++{
- a := 0; b:= 0
- fmt.Scan(&a,&b)
- g[a].edges = append(g[a].edges,b)
- if a == b{
- continue
- }else{
- g[b].edges = append(g[b].edges,a)
- }
- }
- }
- func init_graph(g []Vertex) {
- for i:=0; i < len(g); i++{
- g[i].used = false
- g[i].tin = 0
- g[i].fup = 0
- }
- }
- func min(lhs, rhs int) int{
- if lhs < rhs{
- return lhs
- }else{
- return rhs
- }
- }
- func main(){
- var bridge, time, n, m int
- var DfsInner func(v,anc int)
- fmt.Scan(&n,&m)
- bridge = 0
- time = 1
- Graph := make([]Vertex,n)
- init_graph(Graph)
- DfsInner = func(v, anc int) {
- Graph[v].used = true
- Graph[v].tin = time; Graph[v].fup = time; time++
- for _,to := range Graph[v].edges{
- if to == anc{
- continue
- }
- if !Graph[to].used{
- DfsInner(to,v)
- Graph[v].fup = min(Graph[v].fup, Graph[to].fup)
- if Graph[to].fup > Graph[v].tin{bridge++}
- }else{
- Graph[v].fup = min(Graph[v].fup,Graph[to].tin)
- }
- }
- }
- filling_edge(m,Graph)
- for i:=0;i<n; i++ {if !Graph[i].used{DfsInner(i,-1)}}
- fmt.Printf("%d\n",bridge)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement