結果

問題 No.1254 補強への架け橋
ユーザー ccppjsrbccppjsrb
提出日時 2020-10-09 23:48:19
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 2,448 bytes
コンパイル時間 12,113 ms
コンパイル使用メモリ 207,384 KB
実行使用メモリ 42,988 KB
最終ジャッジ日時 2023-09-27 20:06:51
合計ジャッジ時間 21,753 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 WA -
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 WA -
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 WA -
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 WA -
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 WA -
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 1 ms
4,380 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 1 ms
4,380 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 1 ms
4,376 KB
testcase_50 AC 2 ms
4,376 KB
testcase_51 AC 2 ms
4,380 KB
testcase_52 WA -
testcase_53 AC 1 ms
4,380 KB
testcase_54 AC 2 ms
4,376 KB
testcase_55 AC 2 ms
4,380 KB
testcase_56 AC 2 ms
4,376 KB
testcase_57 AC 2 ms
4,376 KB
testcase_58 AC 2 ms
4,380 KB
testcase_59 AC 1 ms
4,376 KB
testcase_60 AC 1 ms
4,376 KB
testcase_61 WA -
testcase_62 AC 1 ms
4,380 KB
testcase_63 WA -
testcase_64 AC 2 ms
4,380 KB
testcase_65 AC 4 ms
5,604 KB
testcase_66 AC 4 ms
4,376 KB
testcase_67 AC 2 ms
4,376 KB
testcase_68 WA -
testcase_69 AC 5 ms
5,616 KB
testcase_70 AC 3 ms
4,376 KB
testcase_71 WA -
testcase_72 AC 5 ms
5,608 KB
testcase_73 AC 3 ms
4,376 KB
testcase_74 AC 5 ms
5,612 KB
testcase_75 WA -
testcase_76 AC 2 ms
4,380 KB
testcase_77 AC 3 ms
4,380 KB
testcase_78 AC 5 ms
5,552 KB
testcase_79 AC 5 ms
5,616 KB
testcase_80 WA -
testcase_81 AC 6 ms
5,620 KB
testcase_82 AC 5 ms
5,560 KB
testcase_83 AC 77 ms
16,200 KB
testcase_84 AC 85 ms
15,616 KB
testcase_85 AC 47 ms
12,332 KB
testcase_86 WA -
testcase_87 WA -
testcase_88 AC 11 ms
5,176 KB
testcase_89 AC 76 ms
16,160 KB
testcase_90 AC 47 ms
12,524 KB
testcase_91 AC 37 ms
9,604 KB
testcase_92 WA -
testcase_93 AC 61 ms
14,104 KB
testcase_94 WA -
testcase_95 WA -
testcase_96 WA -
testcase_97 AC 31 ms
8,896 KB
testcase_98 AC 68 ms
15,572 KB
testcase_99 WA -
testcase_100 WA -
testcase_101 WA -
testcase_102 AC 8 ms
5,564 KB
testcase_103 AC 20 ms
6,588 KB
testcase_104 AC 26 ms
8,748 KB
testcase_105 WA -
testcase_106 WA -
testcase_107 WA -
testcase_108 AC 77 ms
15,648 KB
testcase_109 AC 59 ms
14,036 KB
testcase_110 AC 57 ms
13,336 KB
testcase_111 WA -
testcase_112 AC 24 ms
8,300 KB
testcase_113 WA -
testcase_114 AC 33 ms
9,316 KB
testcase_115 AC 12 ms
5,328 KB
testcase_116 AC 38 ms
9,764 KB
testcase_117 AC 24 ms
8,288 KB
testcase_118 AC 68 ms
15,448 KB
testcase_119 WA -
testcase_120 WA -
testcase_121 AC 20 ms
8,008 KB
testcase_122 WA -
testcase_123 AC 1 ms
4,380 KB
testcase_124 AC 95 ms
42,988 KB
testcase_125 AC 95 ms
42,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"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)
	g := newGraph(n)
	for i := 0; i < n; i++ {
		a := getNextInt(scanner) - 1
		b := getNextInt(scanner) - 1
		g.AppendEdge(a, b, i)
		g.AppendEdge(b, a, i)
	}
	var dfs func(int, int)
	bb := map[int]bool{}
	dfs = func(now, p int) {
		if g.v[now].visit {
			return
		}
		g.v[now].visit = true
		g.v[now].deg = 1
		for _, e := range g.e[now] {
			if e.to == p {
				continue
			}
			if !g.v[e.to].visit {
				dfs(e.to, now)
			}
			if g.v[e.to].deg == 0 {
				bb[e.id] = true
			}
			g.v[now].deg += g.v[e.to].deg
		}
		if g.v[now].deg == 1 {
			g.v[now].deg--
		}
	}
	dfs(0, -1)
	for i := 0; i < n; i++ {
		g.v[i].visit = false
		g.v[i].deg = 0
	}
	dfs(n-1, -1)
	fmt.Fprintln(writer, n-len(bb))
	if len(bb) == n {
		return
	}
	sep := ""
	for i := 0; i < n; i++ {
		if bb[i] {
			continue
		}
		fmt.Fprintf(writer, "%s%d", sep, i+1)
		sep = " "
	}
	fmt.Fprintln(writer, "")
}

type vertex struct {
	visit bool
	deg   int
}
type edge struct {
	to, id int
}
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) {
	g.e[from] = append(g.e[from], edge{
		to: to,
		id: id,
	})
}
0