← Home
```go
package main

import (
	"bufio"
	"fmt"
	"os"
)

type Edge struct {
	u, v int
	w    int64
}

type Adj struct {
	to int
	id int
}

type Scanner struct {
	r *bufio.Reader
}

func NewScanner() *Scanner {
	return &Scanner{r: bufio.NewReader(os.Stdin)}
}

func (s *Scanner) nextInt() int {
	sign := 1
	val := 0
	c, _ := s.r.ReadByte()
	for (c < '0' || c > '9') && c != '-' {
		c, _ = s.r.ReadByte()
	}
	if c == '-' {
		sign = -1
		c, _ = s.r.ReadByte()
	}
	for c >= '0' && c <= '9' {
		val = val*10 + int(c-'0')
		c, _ = s.r.ReadByte()
	}
	return val * sign
}

func (s *Scanner) nextInt64() int64 {
	sign := int64(1)
	var val int64 = 0
	c, _ := s.r.ReadByte()
	for (c < '0' || c > '9') && c != '-' {
		c, _ = s.r.ReadByte()
	}
	if c == '-' {
		sign = -1
		c, _ = s.r.ReadByte()
	}
	for c >= '0' && c <= '9' {
		val = val*10 + int64(c-'0')
		c, _ = s.r.ReadByte()
	}
	return val * sign
}

var (
	n, m int
	s, t int
	edges []Edge
	g     [][]Adj
)

func bfsPath(s, t int) ([]int, bool, []int, []int) {
	parentEdge := make([]int, n+1)
	parent := make([]int, n+1)
	vis := make([]bool, n+1)
	q := make([]int, 0)
	head := 0
	vis[s] = true
	q = append(q, s)
	for head < len(q) {
		v := q[head]
		head++
		if v == t {
			break
		}
		for _, e := range g[v] {
			to := e.to
			if vis[to] {
				continue
			}
			vis[to] = true
			parent[to] = v
			parentEdge[to] = e.id
			q = append(q, to)
		}
	}
	if !vis[t] {
		return nil, false, parentEdge, parent
	}
	path := make([]int, 0)
	cur := t
	for cur != s {
		eid := parentEdge[cur]
		path = append(path, eid)
		if edges[eid].u == cur {
			cur = edges[eid].v
		} else {
			cur = edges[eid].u
		}
	}
	return path, true, parentEdge, parent
}

type Bridge struct {
	p, c int
	id   int
}

type TarjanRes struct {
	disconnected bool
	minBridgeID  int
	minBridgeW   int64
}

func solveWithBan(ban int, S, T int) TarjanRes {
	tin := make([]int, n+1)
	low := make([]int, n+1)
	tout := make([]int, n+1)
	parentEdge := make([]int, n+1)
	parent := make([]int, n+1)
	compId := make([]int, n+1)
	var time int
	var cc int
	bridges := make([]Bridge, 0)
	var dfs func(v int, root int)
	dfs = func(v int, root int) {
		ccId := root
		compId[v] = ccId
		time++
		tin[v] = time
		low[v] = tin[v]
		for _, e := range g[v] {
			if e.id == ban {
				continue
			}
			to := e.to
			if e.id == parentEdge[v] {
				continue
			}
			if tin[to] != 0 {
				if tin[to] < low[v] {
					low[v] = tin[to]
				}
			} else {
				parent[to] = v
				parentEdge[to] = e.id
				dfs(to, ccId)
				if low[to] < low[v] {
					low[v] = low[to]
				}
				if low[to] > tin[v] {
					bridges = append(bridges, Bridge{p: v, c: to, id: e.id})
				}
			}
		}
		time++
		tout[v] = time
	}
	for i := 1; i <= n; i++ {
		if tin[i] == 0 {
			cc++
			dfs(i, cc)
		}
	}
	disconnected := compId[S] != compId[T]
	const INF int64 = 1<<62
	minW := INF
	minID := 0
	if !disconnected {
		isAnc := func(a, b int) bool {
			return tin[a] <= tin[b] && tout[b] <= tout[a] && compId[a] == compId[b]
		}
		for _, br := range bridges {
			if compId[br.c] != compId[S] {
				continue
			}
			inS := isAnc(br.c, S)
			inT := isAnc(br.c, T)
			if inS != inT {
				w := edges[br.id].w
				if w < minW {
					minW = w
					minID = br.id
				}
			}
		}
	}
	return TarjanRes{
		disconnected: disconnected,
		minBridgeID:  minID,
		minBridgeW:   minW,
	}
}

func main() {
	in := NewScanner()
	n = in.nextInt()
	m = in.nextInt()
	s = in.nextInt()
	t = in.nextInt()
	edges = make([]Edge, m+1)
	g = make([][]Adj, n+1)
	for i := 1; i <= m; i++ {
		x := in.nextInt()
		y := in.nextInt()
		w := in.nextInt64()
		edges[i] = Edge{u: x, v: y, w: w}
		g[x] = append(g[x], Adj{to: y, id: i})
		g[y] = append(g[y], Adj{to: x, id: i})
	}

	// Check initial connectivity and get one s-t path
	path, ok, _, _ := bfsPath(s, t)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	if !ok {
		fmt.Fprintln(out, 0)
		fmt.Fprintln(out, 0)
		fmt.Fprintln(out)
		return
	}

	const INF int64 = 1<<62
	bestCost := INF
	var bestEdges []int

	// Try removing one edge from the found path, then possibly a second bridge
	for _, eid := range path {
		res := solveWithBan(eid, s, t)
		// single-edge
		if res.disconnected {
			if edges[eid].w < bestCost {
				bestCost = edges[eid].w
				bestEdges = []int{eid}
			}
		} else {
			if res.minBridgeID != 0 {
				total := edges[eid].w + res.minBridgeW
				if total < bestCost {
					bestCost = total
					bestEdges = []int{eid, res.minBridgeID}
				}
			}
		}
	}

	if bestCost >= INF {
		fmt.Fprintln(out, -1)
		return
	}
	fmt.Fprintln(out, bestCost)
	fmt.Fprintln(out, len(bestEdges))
	if len(bestEdges) > 0 {
		for i, id := range bestEdges {
			if i > 0 {
				fmt.Fprint(out, " ")
			}
			fmt.Fprint(out, id)
		}
		fmt.Fprintln(out)
	} else {
		fmt.Fprintln(out)
	}
}
```