結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー ccppjsrbccppjsrb
提出日時 2020-05-29 22:23:25
言語 Go
(1.22.1)
結果
MLE  
実行時間 -
コード長 3,167 bytes
コンパイル時間 12,588 ms
コンパイル使用メモリ 219,016 KB
実行使用メモリ 813,992 KB
最終ジャッジ日時 2024-04-23 23:16:42
合計ジャッジ時間 13,864 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 113 ms
18,636 KB
testcase_03 AC 169 ms
32,388 KB
testcase_04 AC 173 ms
33,408 KB
testcase_05 MLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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
}
0