結果

問題 No.1582 Vertexes vs Edges
ユーザー titiatitia
提出日時 2021-07-02 23:14:27
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 324 ms / 2,000 ms
コード長 763 bytes
コンパイル時間 121 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 30,720 KB
最終ジャッジ日時 2024-06-29 13:02:35
合計ジャッジ時間 6,865 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
10,880 KB
testcase_01 AC 26 ms
10,752 KB
testcase_02 AC 28 ms
10,752 KB
testcase_03 AC 29 ms
10,624 KB
testcase_04 AC 35 ms
11,264 KB
testcase_05 AC 244 ms
28,160 KB
testcase_06 AC 36 ms
11,520 KB
testcase_07 AC 55 ms
13,184 KB
testcase_08 AC 128 ms
19,456 KB
testcase_09 AC 228 ms
27,136 KB
testcase_10 AC 151 ms
21,120 KB
testcase_11 AC 39 ms
11,904 KB
testcase_12 AC 114 ms
17,664 KB
testcase_13 AC 168 ms
21,760 KB
testcase_14 AC 175 ms
22,144 KB
testcase_15 AC 230 ms
26,240 KB
testcase_16 AC 123 ms
18,176 KB
testcase_17 AC 165 ms
21,632 KB
testcase_18 AC 270 ms
29,440 KB
testcase_19 AC 172 ms
22,400 KB
testcase_20 AC 155 ms
20,864 KB
testcase_21 AC 135 ms
19,968 KB
testcase_22 AC 240 ms
27,520 KB
testcase_23 AC 101 ms
16,768 KB
testcase_24 AC 61 ms
13,568 KB
testcase_25 AC 142 ms
19,456 KB
testcase_26 AC 111 ms
17,664 KB
testcase_27 AC 224 ms
25,856 KB
testcase_28 AC 86 ms
15,488 KB
testcase_29 AC 203 ms
23,424 KB
testcase_30 AC 130 ms
18,944 KB
testcase_31 AC 200 ms
23,680 KB
testcase_32 AC 102 ms
16,384 KB
testcase_33 AC 315 ms
30,592 KB
testcase_34 AC 324 ms
30,720 KB
testcase_35 AC 316 ms
30,464 KB
testcase_36 AC 26 ms
10,752 KB
testcase_37 AC 25 ms
10,624 KB
testcase_38 AC 25 ms
10,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N=int(input())
E=[[] for i in range(N)]
for i in range(N-1):
    x,y=map(int,input().split())
    x-=1
    y-=1
    E[x].append(y)
    E[y].append(x)

N+=1 # ROOTの親の点を一つ余計に見るため、総ノード数を一つ増やしておく
ROOT=0

QUE=[ROOT] 
Parent=[-1]*(N+1)
Parent[ROOT]=N # ROOTの親を定めておく.
TOP_SORT=[] # トポロジカルソート

while QUE: # トポロジカルソートと同時に親を見つける
    x=QUE.pop()
    TOP_SORT.append(x)
    for to in E[x]:
        if Parent[to]==-1:
            Parent[to]=x
            QUE.append(to)

USE=[0]*(N+2)
ANS=0

for x in TOP_SORT[::-1]:
    if USE[x]==0:
        USE[Parent[x]]=2
    elif USE[x]==2:
        ANS+=1

print(ANS)
0