結果

問題 No.977 アリス仕掛けの摩天楼
ユーザー naipia
提出日時 2020-01-31 21:53:46
言語 Go
(1.23.4)
結果
WA  
実行時間 -
コード長 1,503 bytes
コンパイル時間 14,396 ms
コンパイル使用メモリ 227,088 KB
実行使用メモリ 9,844 KB
最終ジャッジ日時 2024-09-17 08:00:42
合計ジャッジ時間 13,976 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 24 WA * 2
権限があれば一括ダウンロードができます

ソースコード

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

	for i := 0; i < n; i++ {
		if done[i] {
			continue
		}
		queue := make([]int, 0)
		queue = append(queue,i)
		done[i] = true
		c++

		for len(queue) != 0 {
			next := queue[0]
			for _, e := range s[next] {
				if done[e] {
					continue
				}

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

	if c == 1 {
		fmt.Println("Bob")
	} else {
		fmt.Println("Alice")
	}
}
0