package main import ( "bufio" "container/heap" "fmt" "math" "os" "strconv" ) func getScanner(fp *os.File) *bufio.Scanner { scanner := bufio.NewScanner(fp) scanner.Split(bufio.ScanWords) scanner.Buffer(make([]byte, 1000005), 1000005) return scanner } func getNextString(scanner *bufio.Scanner) string { scanner.Scan() return scanner.Text() } func getNextInt(scanner *bufio.Scanner) int { i, _ := strconv.Atoi(getNextString(scanner)) return i } func getNextInt64(scanner *bufio.Scanner) int64 { i, _ := strconv.ParseInt(getNextString(scanner), 10, 64) return i } func getNextUint64(scanner *bufio.Scanner) uint64 { i, _ := strconv.ParseUint(getNextString(scanner), 10, 64) return i } func getNextFloat64(scanner *bufio.Scanner) float64 { i, _ := strconv.ParseFloat(getNextString(scanner), 64) return i } func main() { fp := os.Stdin wfp := os.Stdout cnt := 0 if os.Getenv("MASPY") == "ますピ" { fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT")) cnt = 1 } if os.Getenv("MASPYPY") == "ますピッピ" { wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10")) } scanner := getScanner(fp) writer := bufio.NewWriter(wfp) solve(scanner, writer) for i := 0; i < cnt; i++ { fmt.Fprintln(writer, "-----------------------------------") solve(scanner, writer) } writer.Flush() } func solve(scanner *bufio.Scanner, writer *bufio.Writer) { n := getNextInt(scanner) m := getNextInt(scanner) x := getNextInt(scanner) - 1 y := getNextInt(scanner) - 1 g := newGraph(n) pp := make([]int, n) qq := make([]int, n) for i := 0; i < n; i++ { pp[i] = getNextInt(scanner) qq[i] = getNextInt(scanner) } for i := 0; i < m; i++ { p := getNextInt(scanner) - 1 q := getNextInt(scanner) - 1 w := (pp[p]-pp[q])*(pp[p]-pp[q]) + (qq[p]-qq[q])*(qq[p]-qq[q]) g.appendEdge(p, q, i, math.Sqrt(float64(w))) g.appendEdge(q, p, i, math.Sqrt(float64(w))) } dd := &daikes{} heap.Init(dd) heap.Push(dd, newDaike(x, 0.0)) ww := make([]float64, n) for i := 0; i < n; i++ { ww[i] = math.MaxFloat64 } for dd.Len() > 0 { d := heap.Pop(dd).(daike) if ww[d.i] < d.w { continue } ww[d.i] = d.w for _, e := range g.e[d.i] { if e.w+d.w > ww[e.to] { continue } ww[e.to] = e.w + d.w heap.Push(dd, newDaike(e.to, e.w+d.w)) } } fmt.Fprintf(writer, "%.9f\n", ww[y]) } func newDaike(i int, w float64) daike { return daike{ i: i, w: w, } } type daike struct { i int w float64 } type daikes []daike func (h daikes) Len() int { return len(h) } func (h daikes) Less(i, j int) bool { return h[i].w < h[j].w } func (h daikes) Swap(i, j int) { h[i], h[j] = h[j], h[i] } func (h *daikes) Push(x interface{}) { *h = append(*h, x.(daike)) } func (h *daikes) Pop() interface{} { old := *h n := len(old) x := old[n-1] *h = old[0 : n-1] return x } type graph struct { v []*vertex e [][]*edge } func newGraph(n int) *graph { return &graph{ v: make([]*vertex, n), e: make([][]*edge, n), } } func (g *graph) appendEdge(from, to, id int, w float64) { g.e[from] = append(g.e[from], &edge{ to: to, id: id, w: w, }) } type vertex struct { } type edge struct { to, id int w float64 }