結果

問題 No.806 木を道に
ユーザー るさるさ
提出日時 2019-04-07 15:32:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 892 ms / 2,000 ms
コード長 741 bytes
コンパイル時間 98 ms
コンパイル使用メモリ 11,004 KB
実行使用メモリ 52,280 KB
最終ジャッジ日時 2023-09-09 11:19:44
合計ジャッジ時間 11,544 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,664 KB
testcase_01 AC 16 ms
7,888 KB
testcase_02 AC 16 ms
7,712 KB
testcase_03 AC 16 ms
7,712 KB
testcase_04 AC 16 ms
7,876 KB
testcase_05 AC 17 ms
7,880 KB
testcase_06 AC 17 ms
7,724 KB
testcase_07 AC 16 ms
7,880 KB
testcase_08 AC 16 ms
7,728 KB
testcase_09 AC 15 ms
7,836 KB
testcase_10 AC 161 ms
18,548 KB
testcase_11 AC 133 ms
16,192 KB
testcase_12 AC 674 ms
43,380 KB
testcase_13 AC 467 ms
34,224 KB
testcase_14 AC 647 ms
41,708 KB
testcase_15 AC 687 ms
43,732 KB
testcase_16 AC 210 ms
21,184 KB
testcase_17 AC 580 ms
39,164 KB
testcase_18 AC 62 ms
11,332 KB
testcase_19 AC 162 ms
18,232 KB
testcase_20 AC 611 ms
39,044 KB
testcase_21 AC 288 ms
25,464 KB
testcase_22 AC 860 ms
51,704 KB
testcase_23 AC 892 ms
51,704 KB
testcase_24 AC 325 ms
30,972 KB
testcase_25 AC 509 ms
41,164 KB
testcase_26 AC 188 ms
21,288 KB
testcase_27 AC 666 ms
52,280 KB
testcase_28 AC 30 ms
9,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Node:
	def __init__(self):
		self.edge=[]
		self.degree=0
	
	def add_edge(self,new_edge):
		self.edge.append(new_edge)
		self.degree+=1


class Edge:
	def __init__(self,node_a,node_b):
		node_a.add_edge(self)
		node_b.add_edge(self)
		self.node=(node_a,node_b)


class Graph:
	def __init__(self):
		self.node={}
		self.edge=[]
	
	def add_edge(self,new_edge):
		if not new_edge[0] in self.node:
			self.node[new_edge[0]]=Node()
		if not new_edge[1] in self.node:
			self.node[new_edge[1]]=Node()
		self.edge.append(Edge(self.node[new_edge[0]],self.node[new_edge[1]]))


n=int(input())
g=Graph()
for i in range(n-1):
    g.add_edge(list(map(int,input().split())))

c=-2
for i in g.node:
    if g.node[i].degree==1:
        c+=1

print(c)
0