結果

問題 No.1382 Travel in Mitaru city
ユーザー aru aruaru aru
提出日時 2021-02-13 11:03:20
言語 Go
(1.22.1)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 2,591 bytes
コンパイル時間 10,633 ms
コンパイル使用メモリ 213,892 KB
実行使用メモリ 16,436 KB
最終ジャッジ日時 2023-09-27 19:18:11
合計ジャッジ時間 16,303 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 21 ms
7,956 KB
testcase_07 AC 17 ms
7,740 KB
testcase_08 AC 11 ms
5,540 KB
testcase_09 AC 22 ms
7,968 KB
testcase_10 AC 20 ms
7,952 KB
testcase_11 AC 51 ms
9,996 KB
testcase_12 AC 54 ms
10,076 KB
testcase_13 AC 56 ms
10,032 KB
testcase_14 AC 49 ms
10,032 KB
testcase_15 AC 47 ms
10,036 KB
testcase_16 AC 76 ms
12,200 KB
testcase_17 AC 77 ms
12,192 KB
testcase_18 AC 77 ms
12,164 KB
testcase_19 AC 77 ms
12,164 KB
testcase_20 AC 77 ms
12,160 KB
testcase_21 AC 77 ms
12,160 KB
testcase_22 AC 79 ms
12,160 KB
testcase_23 AC 81 ms
12,208 KB
testcase_24 AC 81 ms
12,168 KB
testcase_25 AC 76 ms
12,164 KB
testcase_26 AC 68 ms
12,164 KB
testcase_27 AC 72 ms
12,160 KB
testcase_28 AC 66 ms
12,188 KB
testcase_29 AC 66 ms
12,184 KB
testcase_30 AC 61 ms
12,160 KB
testcase_31 AC 46 ms
10,008 KB
testcase_32 AC 55 ms
12,148 KB
testcase_33 AC 51 ms
12,096 KB
testcase_34 AC 36 ms
7,916 KB
testcase_35 AC 20 ms
7,620 KB
testcase_36 AC 39 ms
10,032 KB
testcase_37 AC 7 ms
4,380 KB
testcase_38 AC 45 ms
12,100 KB
testcase_39 AC 10 ms
5,512 KB
testcase_40 AC 29 ms
7,924 KB
testcase_41 AC 32 ms
10,008 KB
testcase_42 AC 41 ms
12,100 KB
testcase_43 AC 36 ms
10,016 KB
testcase_44 AC 12 ms
5,536 KB
testcase_45 AC 36 ms
9,996 KB
testcase_46 AC 19 ms
7,848 KB
testcase_47 AC 70 ms
14,404 KB
testcase_48 AC 51 ms
14,332 KB
testcase_49 AC 78 ms
16,436 KB
testcase_50 AC 31 ms
9,960 KB
testcase_51 AC 44 ms
10,024 KB
testcase_52 AC 54 ms
12,124 KB
testcase_53 AC 12 ms
5,516 KB
testcase_54 AC 21 ms
7,716 KB
testcase_55 AC 53 ms
12,104 KB
testcase_56 AC 15 ms
5,536 KB
testcase_57 AC 33 ms
7,920 KB
testcase_58 AC 4 ms
4,380 KB
testcase_59 AC 14 ms
5,532 KB
testcase_60 AC 50 ms
12,100 KB
testcase_61 AC 2 ms
4,376 KB
testcase_62 AC 1 ms
4,380 KB
testcase_63 AC 5 ms
4,376 KB
testcase_64 AC 2 ms
4,380 KB
testcase_65 AC 1 ms
4,380 KB
testcase_66 AC 2 ms
4,376 KB
testcase_67 AC 2 ms
4,376 KB
testcase_68 AC 2 ms
4,376 KB
testcase_69 AC 2 ms
4,376 KB
testcase_70 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

func getI() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getI()
	}
	return ret
}

func getS() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

// min for n entry
func nmin(a ...int) int {
	ret := a[0]
	for _, e := range a {
		ret = min(ret, e)
	}
	return ret
}

// max for n entry
func nmax(a ...int) int {
	ret := a[0]
	for _, e := range a {
		ret = max(ret, e)
	}
	return ret
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

type pqi struct{ a, to int }

type priorityQueue []pqi

func (pq priorityQueue) Len() int            { return len(pq) }
func (pq priorityQueue) Swap(i, j int)       { pq[i], pq[j] = pq[j], pq[i] }
func (pq priorityQueue) Less(i, j int) bool  { return pq[i].a < pq[j].a }
func (pq *priorityQueue) Push(x interface{}) { *pq = append(*pq, x.(pqi)) }
func (pq *priorityQueue) Pop() interface{} {
	x := (*pq)[len(*pq)-1]
	*pq = (*pq)[0 : len(*pq)-1]
	return x
}

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, math.MaxInt32)
	// this template is new version.
	// use getI(), getS(), getInts(), getF()
	N, M, S, _ := getI(), getI(), getI()-1, getI()-1
	p := getInts(N)
	node := make([][]int, N)
	for i := 0; i < M; i++ {
		a, b := getI()-1, getI()-1
		node[a] = append(node[a], b)
		node[b] = append(node[b], a)
	}

	used := make([]bool, N)
	pq := priorityQueue{}
	heap.Push(&pq, pqi{-p[S], S})
	used[S] = true
	x, y := p[S], 0
	for len(pq) != 0 {
		cur := pq[0]
		heap.Pop(&pq)
		pi := -cur.a
		if pi < x {
			x = pi
			y++
		}
		for _, v := range node[cur.to] {
			if used[v] {
				continue
			}
			used[v] = true
			heap.Push(&pq, pqi{-p[v], v})
		}
	}
	out(y)
}
0