結果

問題 No.92 逃走経路
ユーザー ccppjsrbccppjsrb
提出日時 2020-06-02 15:59:28
言語 Go
(1.22.1)
結果
AC  
実行時間 23 ms / 5,000 ms
コード長 2,285 bytes
コンパイル時間 11,649 ms
コンパイル使用メモリ 204,304 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-15 17:18:06
合計ジャッジ時間 12,671 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 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,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 23 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 22 ms
4,380 KB
testcase_11 AC 22 ms
4,380 KB
testcase_12 AC 23 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"math/big"
	"os"
	"strconv"
	"strings"
)

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)
	k := getNextInt(scanner)
	pp := map[int][]pair{}
	for i := 0; i < m; i++ {
		a := getNextInt(scanner) - 1
		b := getNextInt(scanner) - 1
		c := getNextInt(scanner)
		pp[c] = append(pp[c], newPair(a, b))
	}
	dp := make([]*big.Int, k+1)
	for i := 0; i < k+1; i++ {
		dp[i] = big.NewInt(0)
	}
	for i := 0; i < n; i++ {
		dp[0].SetBit(dp[0], i, 1)
	}
	for i := 0; i < k; i++ {
		d := getNextInt(scanner)
		for _, p := range pp[d] {
			if dp[i].Bit(p[0]) == 1 {
				dp[i+1].SetBit(dp[i+1], p[1], 1)
			}
			if dp[i].Bit(p[1]) == 1 {
				dp[i+1].SetBit(dp[i+1], p[0], 1)
			}
		}
	}
	ans := make([]string, 0)
	for i := 0; i < n; i++ {
		if dp[k].Bit(i) == 1 {
			ans = append(ans, fmt.Sprintf("%d", i+1))
		}
	}
	fmt.Fprintln(writer, len(ans))
	fmt.Fprintln(writer, strings.Join(ans, " "))
}

func newPair(a, b int) pair {
	return pair{a, b}
}

type pair [2]int
0