結果
問題 | No.806 木を道に |
ユーザー | 双六 |
提出日時 | 2019-04-06 07:56:20 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 450 ms / 2,000 ms |
コード長 | 533 bytes |
コンパイル時間 | 72 ms |
コンパイル使用メモリ | 10,912 KB |
実行使用メモリ | 30,660 KB |
最終ジャッジ日時 | 2023-09-05 17:26:34 |
合計ジャッジ時間 | 6,301 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 18 ms
8,660 KB |
testcase_01 | AC | 18 ms
8,512 KB |
testcase_02 | AC | 18 ms
8,484 KB |
testcase_03 | AC | 18 ms
8,680 KB |
testcase_04 | AC | 18 ms
8,608 KB |
testcase_05 | AC | 19 ms
8,688 KB |
testcase_06 | AC | 18 ms
8,448 KB |
testcase_07 | AC | 18 ms
8,508 KB |
testcase_08 | AC | 18 ms
8,652 KB |
testcase_09 | AC | 18 ms
8,492 KB |
testcase_10 | AC | 107 ms
13,884 KB |
testcase_11 | AC | 94 ms
12,444 KB |
testcase_12 | AC | 371 ms
24,528 KB |
testcase_13 | AC | 273 ms
20,824 KB |
testcase_14 | AC | 367 ms
23,768 KB |
testcase_15 | AC | 382 ms
24,800 KB |
testcase_16 | AC | 144 ms
14,696 KB |
testcase_17 | AC | 328 ms
22,820 KB |
testcase_18 | AC | 50 ms
9,876 KB |
testcase_19 | AC | 111 ms
13,540 KB |
testcase_20 | AC | 330 ms
22,824 KB |
testcase_21 | AC | 189 ms
16,460 KB |
testcase_22 | AC | 450 ms
29,232 KB |
testcase_23 | AC | 445 ms
29,332 KB |
testcase_24 | AC | 215 ms
19,452 KB |
testcase_25 | AC | 313 ms
23,728 KB |
testcase_26 | AC | 130 ms
14,888 KB |
testcase_27 | AC | 404 ms
30,660 KB |
testcase_28 | AC | 29 ms
9,212 KB |
ソースコード
from collections import defaultdict class Graph(object): def __init__(self): self.graph = defaultdict(list) def __len__(self): return len(self.graph) def add_edge(self, a, b): self.graph[a].append(b) def get_nodes(self): return self.graph.keys() g_a = Graph() N = int(input()) for i in range(N - 1): a, b = list(map(int, input().split())) g_a.add_edge(a, b) g_a.add_edge(b, a) ans = -2 for i in g_a.graph: if len(g_a.graph[i]) == 1: ans += 1 print(ans)