東京大学プログラミングコンテスト2014

Submission #6919636

Source codeソースコード

from collections import defaultdict
import sys
sys.setrecursionlimit(10**7)


n = int(input())
edge = defaultdict(list)
for i in range(n):
    a, b = map(int, input().split())
    edge[a].append(b)
    edge[b].append(a)

def dfs(now, prev, visited = []):
    if now in visited:
        return len(visited) - visited.index(now)
    else:
        for e in edge[now]:
            if e == prev:
                continue
            visited.append(now)
            ret = dfs(e, now, visited)
            if ret > 0:
                return ret
            visited.pop()
    return 0

loop_length = dfs(1, 1)
ans_min = 1
ans_max = n
if loop_length == n:
    ans_min = 2

if loop_length % 2 == 1:
    ans_max = n-1

print(str(ans_min) + ' ' + str(ans_max))

Submission

Task問題 C - 最小カットと最大カット
User nameユーザ名 tsb2b
Created time投稿日時
Language言語 PyPy3 (2.4.0)
Status状態 TLE
Score得点 0
Source lengthソースコード長 785 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

Test case

Set

Set name Score得点 / Max score Cases
All 0 / 100 scrambled_00.txt,scrambled_01.txt,scrambled_02.txt,scrambled_03.txt,scrambled_04.txt,scrambled_05.txt,scrambled_06.txt,scrambled_07.txt,scrambled_08.txt,scrambled_09.txt,scrambled_10.txt,scrambled_11.txt,scrambled_12.txt,scrambled_13.txt,scrambled_14.txt,scrambled_15.txt,scrambled_16.txt,scrambled_17.txt,scrambled_18.txt,scrambled_19.txt,scrambled_20.txt,scrambled_21.txt,scrambled_22.txt,scrambled_23.txt,scrambled_24.txt,scrambled_25.txt,scrambled_26.txt,scrambled_27.txt,scrambled_28.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
scrambled_00.txt AC 167 ms 38512 KB
scrambled_01.txt AC 162 ms 38384 KB
scrambled_02.txt AC 162 ms 38256 KB
scrambled_03.txt TLE
scrambled_04.txt TLE
scrambled_05.txt AC 1930 ms 96828 KB
scrambled_06.txt AC 997 ms 78680 KB
scrambled_07.txt TLE
scrambled_08.txt AC 768 ms 74328 KB
scrambled_09.txt AC 1047 ms 77016 KB
scrambled_10.txt AC 622 ms 71256 KB
scrambled_11.txt AC 398 ms 54104 KB
scrambled_12.txt AC 543 ms 61528 KB
scrambled_13.txt AC 566 ms 61400 KB
scrambled_14.txt AC 831 ms 80344 KB
scrambled_15.txt AC 595 ms 62552 KB
scrambled_16.txt AC 453 ms 56792 KB
scrambled_17.txt AC 429 ms 56280 KB
scrambled_18.txt AC 689 ms 69848 KB
scrambled_19.txt AC 316 ms 50264 KB
scrambled_20.txt AC 587 ms 64856 KB
scrambled_21.txt AC 423 ms 55256 KB
scrambled_22.txt AC 561 ms 60376 KB
scrambled_23.txt AC 451 ms 57432 KB
scrambled_24.txt AC 448 ms 56920 KB
scrambled_25.txt AC 496 ms 58200 KB
scrambled_26.txt AC 460 ms 57688 KB
scrambled_27.txt AC 545 ms 59264 KB
scrambled_28.txt AC 524 ms 58456 KB