結果

問題 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  
実行時間 398 ms / 2,000 ms
コード長 763 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 10,868 KB
実行使用メモリ 28,148 KB
最終ジャッジ日時 2023-09-11 23:40:42
合計ジャッジ時間 7,587 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,796 KB
testcase_01 AC 16 ms
7,816 KB
testcase_02 AC 16 ms
7,788 KB
testcase_03 AC 16 ms
7,788 KB
testcase_04 AC 25 ms
8,788 KB
testcase_05 AC 241 ms
25,796 KB
testcase_06 AC 27 ms
9,068 KB
testcase_07 AC 49 ms
10,728 KB
testcase_08 AC 125 ms
16,840 KB
testcase_09 AC 224 ms
24,556 KB
testcase_10 AC 144 ms
18,656 KB
testcase_11 AC 31 ms
9,280 KB
testcase_12 AC 103 ms
15,312 KB
testcase_13 AC 181 ms
19,304 KB
testcase_14 AC 190 ms
19,556 KB
testcase_15 AC 254 ms
23,564 KB
testcase_16 AC 135 ms
15,708 KB
testcase_17 AC 185 ms
18,844 KB
testcase_18 AC 299 ms
26,828 KB
testcase_19 AC 176 ms
19,848 KB
testcase_20 AC 172 ms
18,268 KB
testcase_21 AC 145 ms
17,360 KB
testcase_22 AC 264 ms
24,728 KB
testcase_23 AC 112 ms
14,232 KB
testcase_24 AC 58 ms
11,108 KB
testcase_25 AC 159 ms
16,948 KB
testcase_26 AC 117 ms
14,904 KB
testcase_27 AC 270 ms
23,324 KB
testcase_28 AC 85 ms
12,816 KB
testcase_29 AC 238 ms
20,972 KB
testcase_30 AC 152 ms
16,128 KB
testcase_31 AC 239 ms
21,388 KB
testcase_32 AC 101 ms
13,984 KB
testcase_33 AC 398 ms
28,148 KB
testcase_34 AC 369 ms
28,012 KB
testcase_35 AC 380 ms
27,960 KB
testcase_36 AC 16 ms
7,816 KB
testcase_37 AC 16 ms
7,732 KB
testcase_38 AC 16 ms
7,768 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