AtCoder Regular Contest 078

Submission #1433142

Source codeソースコード

import sys
from collections import deque
readline = sys.stdin.readline

N = int(readline())
edges = [[] for _ in [None]*N]
for _ in [None]*(N-1):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)


def bfs(n, edges, start):
    dq = deque()
    append, pop = dq.append, dq.popleft
    distances = [None]*n
    distances[start] = 0

    append((start, 0))
    while dq:
        pos, cost = pop()
        cost += 1
        for dest in edges[pos]:
            if distances[dest] is None:
                distances[dest] = cost
                append((dest, cost))

    return distances


fennec_map = bfs(N, edges, 0)
snuke_map = bfs(N, edges, N-1)
fennec = snuke = 0
for f, s in zip(fennec_map, snuke_map):
    if f <= s:
        fennec += 1
    else:
        snuke += 1

print("Fennec" if fennec > snuke else "Snuke")

Submission

Task問題 D - Fennec VS. Snuke
User nameユーザ名 htkb
Created time投稿日時
Language言語 Python3 (3.4.3)
Status状態 AC
Score得点 400
Source lengthソースコード長 896 Byte
File nameファイル名
Exec time実行時間 547 ms
Memory usageメモリ使用量 30172 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - 00_example_01.txt,00_example_02.txt
All 400 / 400 00_example_01.txt,00_example_02.txt,01.txt,02.txt,03.txt,04.txt,05.txt,06.txt,07.txt,08.txt,09.txt,10.txt,11.txt,12.txt,13.txt,14.txt,15.txt,16.txt,17.txt,18.txt,19.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
00_example_01.txt AC 20 ms 3316 KB
00_example_02.txt AC 21 ms 3316 KB
01.txt AC 21 ms 3316 KB
02.txt AC 20 ms 3316 KB
03.txt AC 20 ms 3316 KB
04.txt AC 21 ms 3316 KB
05.txt AC 444 ms 23880 KB
06.txt AC 496 ms 25364 KB
07.txt AC 456 ms 23156 KB
08.txt AC 480 ms 25272 KB
09.txt AC 20 ms 3316 KB
10.txt AC 489 ms 22156 KB
11.txt AC 488 ms 22084 KB
12.txt AC 497 ms 23736 KB
13.txt AC 534 ms 24748 KB
14.txt AC 530 ms 24756 KB
15.txt AC 535 ms 24624 KB
16.txt AC 547 ms 30172 KB
17.txt AC 539 ms 30088 KB
18.txt AC 518 ms 30088 KB
19.txt AC 508 ms 30088 KB