結果
問題 | No.812 Change of Class |
ユーザー | ccppjsrb |
提出日時 | 2020-08-13 22:42:31 |
言語 | Go (1.22.1) |
結果 |
AC
|
実行時間 | 222 ms / 4,000 ms |
コード長 | 2,448 bytes |
コンパイル時間 | 11,664 ms |
コンパイル使用メモリ | 225,068 KB |
実行使用メモリ | 32,984 KB |
最終ジャッジ日時 | 2024-10-09 19:35:56 |
合計ジャッジ時間 | 19,165 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 180 ms
22,388 KB |
testcase_01 | AC | 26 ms
7,940 KB |
testcase_02 | AC | 96 ms
14,188 KB |
testcase_03 | AC | 205 ms
24,752 KB |
testcase_04 | AC | 179 ms
22,760 KB |
testcase_05 | AC | 222 ms
26,732 KB |
testcase_06 | AC | 174 ms
26,816 KB |
testcase_07 | AC | 6 ms
7,888 KB |
testcase_08 | AC | 3 ms
6,816 KB |
testcase_09 | AC | 210 ms
32,984 KB |
testcase_10 | AC | 217 ms
28,828 KB |
testcase_11 | AC | 26 ms
11,828 KB |
testcase_12 | AC | 134 ms
26,844 KB |
testcase_13 | AC | 2 ms
6,816 KB |
testcase_14 | AC | 2 ms
6,816 KB |
testcase_15 | AC | 142 ms
20,584 KB |
testcase_16 | AC | 11 ms
8,248 KB |
testcase_17 | AC | 122 ms
22,712 KB |
testcase_18 | AC | 95 ms
18,472 KB |
testcase_19 | AC | 107 ms
20,584 KB |
testcase_20 | AC | 222 ms
28,824 KB |
testcase_21 | AC | 95 ms
16,528 KB |
testcase_22 | AC | 38 ms
12,412 KB |
testcase_23 | AC | 8 ms
7,856 KB |
testcase_24 | AC | 14 ms
8,364 KB |
testcase_25 | AC | 32 ms
10,392 KB |
testcase_26 | AC | 190 ms
24,620 KB |
testcase_27 | AC | 167 ms
22,572 KB |
testcase_28 | AC | 105 ms
18,608 KB |
testcase_29 | AC | 26 ms
10,428 KB |
testcase_30 | AC | 140 ms
22,640 KB |
testcase_31 | AC | 114 ms
18,276 KB |
testcase_32 | AC | 49 ms
14,456 KB |
testcase_33 | AC | 136 ms
22,628 KB |
testcase_34 | AC | 11 ms
8,260 KB |
testcase_35 | AC | 26 ms
10,640 KB |
testcase_36 | AC | 10 ms
8,404 KB |
testcase_37 | AC | 61 ms
14,884 KB |
testcase_38 | AC | 12 ms
9,716 KB |
testcase_39 | AC | 68 ms
14,972 KB |
testcase_40 | AC | 18 ms
8,640 KB |
testcase_41 | AC | 9 ms
7,784 KB |
testcase_42 | AC | 137 ms
21,136 KB |
testcase_43 | AC | 31 ms
14,524 KB |
testcase_44 | AC | 94 ms
16,936 KB |
testcase_45 | AC | 11 ms
8,548 KB |
testcase_46 | AC | 28 ms
14,380 KB |
testcase_47 | AC | 93 ms
16,848 KB |
testcase_48 | AC | 105 ms
19,048 KB |
testcase_49 | AC | 30 ms
10,484 KB |
testcase_50 | AC | 3 ms
6,820 KB |
testcase_51 | AC | 32 ms
10,508 KB |
testcase_52 | AC | 60 ms
16,916 KB |
testcase_53 | AC | 18 ms
8,652 KB |
testcase_54 | AC | 15 ms
8,524 KB |
testcase_55 | AC | 107 ms
20,348 KB |
testcase_56 | AC | 150 ms
22,372 KB |
testcase_57 | AC | 145 ms
22,360 KB |
testcase_58 | AC | 70 ms
14,080 KB |
testcase_59 | AC | 152 ms
26,524 KB |
testcase_60 | AC | 1 ms
6,816 KB |
testcase_61 | AC | 1 ms
6,816 KB |
testcase_62 | AC | 2 ms
6,820 KB |
ソースコード
package main import ( "bufio" "fmt" "math/bits" "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) g := newGraph(n) for i := 0; i < m; i++ { u := getNextInt(scanner) - 1 v := getNextInt(scanner) - 1 g.appendEdge(u, v, i) g.appendEdge(v, u, i) } q := getNextInt(scanner) for i := 0; i < q; i++ { a := getNextInt(scanner) - 1 dd := make([]int, n) vv := make([]bool, n) pp := make([]pair, 0) pp = append(pp, pair{a, 0}) vv[a] = true for len(pp) > 0 { p := pp[0] pp = pp[1:] dd[p[0]] = p[1] for _, e := range g.e[p[0]] { if vv[e.to] { continue } vv[e.to] = true pp = append(pp, pair{e.to, p[1] + 1}) } } mx := 0 cnt := 0 for j := 0; j < n; j++ { if dd[j] == 0 { continue } cnt++ if mx < dd[j] { mx = dd[j] } } if mx > 0 { mx-- } days := 32 - bits.LeadingZeros32(uint32(mx)) fmt.Fprintln(writer, fmt.Sprintf("%d %d", cnt, days)) } } type pair [2]int type vertex struct { } 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, }) }