結果
問題 | No.848 なかよし旅行 |
ユーザー | ccppjsrb |
提出日時 | 2020-08-17 00:22:43 |
言語 | Go (1.22.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 3,250 bytes |
コンパイル時間 | 14,158 ms |
コンパイル使用メモリ | 221,508 KB |
実行使用メモリ | 49,224 KB |
最終ジャッジ日時 | 2024-10-11 13:25:13 |
合計ジャッジ時間 | 21,854 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | TLE | - |
testcase_01 | -- | - |
testcase_02 | -- | - |
testcase_03 | -- | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
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 | -- | - |
ソースコード
package main import ( "bufio" "container/heap" "fmt" "math" "os" "strconv" ) func configure(scanner *bufio.Scanner) { scanner.Split(bufio.ScanWords) scanner.Buffer(make([]byte, 1000005), 1000005) } func getNextString(scanner *bufio.Scanner) string { scanned := scanner.Scan() if !scanned { panic("scan failed") } 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 getNextFloat64(scanner *bufio.Scanner) float64 { i, _ := strconv.ParseFloat(getNextString(scanner), 64) return i } func main() { fp := os.Stdin wfp := os.Stdout extra := 0 if os.Getenv("I") == "IronMan" { fp, _ = os.Open(os.Getenv("END_GAME")) extra = 100 } scanner := bufio.NewScanner(fp) configure(scanner) writer := bufio.NewWriter(wfp) defer func() { r := recover() if r != nil { fmt.Fprintln(writer, r) } writer.Flush() }() solve(scanner, writer) for i := 0; i < extra; i++ { fmt.Fprintln(writer, "-----------------------------------") solve(scanner, writer) } } func solve(scanner *bufio.Scanner, writer *bufio.Writer) { n := getNextInt(scanner) m := getNextInt(scanner) p := getNextInt(scanner) - 1 q := getNextInt(scanner) - 1 t := getNextInt64(scanner) g := newGraph(n) for i := 0; i < m; i++ { a := getNextInt(scanner) - 1 b := getNextInt(scanner) - 1 c := getNextInt64(scanner) g.appendEdge(a, b, i, c) g.appendEdge(b, a, i, c) } var ans int64 ans = -1 for i := 0; i < n; i++ { g.daike(i) } for i := 0; i < n; i++ { for j := 0; j < n; j++ { together := g.v[0].dd[i] + g.v[j].dd[0] mohu := g.v[i].dd[p] + g.v[p].dd[j] mohumohu := g.v[i].dd[q] + g.v[q].dd[j] if together+max(mohu, mohumohu) > t { continue } if i == p { ans = t break } if ans < t-max(mohu, mohumohu) { ans = t - max(mohu, mohumohu) } } } fmt.Fprintln(writer, ans) } type daike struct { i int c int64 } type daikes []daike func (h daikes) Len() int { return len(h) } func (h daikes) Less(i, j int) bool { return h[i].c < h[j].c } 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 vertex struct { dd []int64 } type edge struct { to, id int c int64 } 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, c int64) { g.e[from] = append(g.e[from], edge{ to: to, id: id, c: c, }) } func (g *graph) daike(s int) { dd := &daikes{} n := len(g.v) g.v[s].dd = make([]int64, n) for i := 0; i < n; i++ { g.v[s].dd[i] = math.MaxInt64 } heap.Push(dd, daike{i: s, c: 0}) for dd.Len() > 0 { p := heap.Pop(dd).(daike) if g.v[s].dd[p.i] <= p.c { continue } g.v[s].dd[p.i] = p.c for _, e := range g.e[p.i] { heap.Push(dd, daike{i: e.to, c: e.c + p.c}) } } } func max(a, b int64) int64 { if a < b { return b } return a }