結果
| 問題 |
No.1582 Vertexes vs Edges
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2021-07-02 23:12:46 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 759 bytes |
| コンパイル時間 | 223 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 30,464 KB |
| 最終ジャッジ日時 | 2024-06-29 13:01:14 |
| 合計ジャッジ時間 | 6,627 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 RE * 7 |
ソースコード
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
ANS=0
for x in TOP_SORT[::-1]:
if USE[x]==0:
USE[Parent[x]]=2
elif USE[x]==2:
ANS+=1
print(ANS)
titia