結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー 👑 naipianaipia
提出日時 2020-01-31 22:29:29
言語 Go
(1.22.1)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 1,705 bytes
コンパイル時間 12,008 ms
コンパイル使用メモリ 220,816 KB
実行使用メモリ 10,028 KB
最終ジャッジ日時 2023-10-17 10:41:43
合計ジャッジ時間 13,558 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 4 ms
4,348 KB
testcase_14 AC 4 ms
4,348 KB
testcase_15 AC 4 ms
4,348 KB
testcase_16 AC 4 ms
4,348 KB
testcase_17 AC 4 ms
4,348 KB
testcase_18 AC 10 ms
5,576 KB
testcase_19 AC 12 ms
5,512 KB
testcase_20 AC 17 ms
5,540 KB
testcase_21 AC 28 ms
5,540 KB
testcase_22 AC 42 ms
7,792 KB
testcase_23 AC 52 ms
9,996 KB
testcase_24 AC 46 ms
10,028 KB
testcase_25 AC 50 ms
10,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)

//•*¨*•.¸¸♪I/O•*¨*•.¸¸♪

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

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanInt64() int64 {
	sc.Scan()
	a,_ := strconv.ParseInt(sc.Text(),10,64)
	return a
}

func scanFloat64() float64 {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return float64(a)
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

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

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪( -ω-)ノ ( ・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	// sc.Buffer(make([]byte, 10000), 100000000)

	n := scanInt()

	s := make([][]int, n)

	for i := 0; i < n-1; i++ {
		u,v := scanInt(),scanInt()
		s[u] = append(s[u],v)
		s[v] = append(s[v],u)
	}

	done := make([]bool, n)
	c := 0
	cyc := 0

	for i := 0; i < n; i++ {
		if done[i] {
			continue
		}
		queue := make([]int, 0)
		queue = append(queue,i)
		done[i] = true
		c++
		if c > 2 {
			fmt.Println("Alice")
			return
		}

		f := true

		for len(queue) != 0 {
			next := queue[0]
			if !(len(s[next]) == 2 || len(s[next]) == 0) {
				f = false
			}

			for _, e := range s[next] {
				if done[e] {
					continue
				}

				done[e] = true
				queue = append(queue, e)
			}
			queue = queue[1:]
		}

		if f {
			cyc++
		}

		if c == 2 && cyc != 2 {
			fmt.Println("Alice")
			return
		}
	}

	fmt.Println("Bob")

	// fmt.Println(c)
}
0