結果
問題 | No.1065 電柱 / Pole (Easy) |
ユーザー | ccppjsrb |
提出日時 | 2020-05-29 22:30:03 |
言語 | Go (1.22.1) |
結果 |
MLE
|
実行時間 | - |
コード長 | 3,314 bytes |
コンパイル時間 | 15,368 ms |
コンパイル使用メモリ | 237,504 KB |
実行使用メモリ | 810,612 KB |
最終ジャッジ日時 | 2024-11-06 05:54:02 |
合計ジャッジ時間 | 19,831 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 170 ms
20,312 KB |
testcase_03 | AC | 214 ms
34,480 KB |
testcase_04 | AC | 211 ms
34,484 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 | -- | - |
ソースコード
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 compare(ww[d.i], d.w) == -1 { continue } ww[d.i] = d.w for _, e := range g.e[d.i] { if compare(ww[e.to], e.w+d.w) == -1 { 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 compare(a, b float64) int { eps := 1e-9 if a > b+eps { return 1 } if b > a+eps { return -1 } return 0 } 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 }