結果
| 問題 | No.3514 Majority Driven Tree |
| コンテスト | |
| ユーザー |
ゼット
|
| 提出日時 | 2026-04-24 22:52:20 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 929 bytes |
| 記録 | |
| コンパイル時間 | 1,703 ms |
| コンパイル使用メモリ | 84,976 KB |
| 実行使用メモリ | 86,624 KB |
| 最終ジャッジ日時 | 2026-04-24 22:52:34 |
| 合計ジャッジ時間 | 7,034 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge4_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | WA * 37 |
ソースコード
N=int(input())
G=[[] for i in range(N)]
R=[set() for i in range(N)]
for i in range(N-1):
a,b=map(int,input().split())
G[a-1].append(b-1)
G[b-1].append(a-1)
R[a-1].add(b-1)
R[b-1].add(a-1)
from collections import deque
S=deque()
dp=[0]*N
used=[False]*N
h=[]
for i in range(N):
if len(G[i])==1:
S.append(i)
used[i]=True
while S:
x=S.pop()
for y in G[x]:
dp[x]+=dp[y]
if len(G[x])-2*dp[x]>2:
dp[x]+=1
h.append(x)
for y in G[x]:
if used[y]==True:
continue
R[y].remove(x)
if len(R[y])==1:
used[y]=True
S.append(y)
used=[False]*N
v=[0]*N
for i in range(N):
v[i]=len(G[i])
S=deque()
for pos in h:
S.append(pos)
used[pos]=True
while S:
x=S.pop()
for y in G[x]:
if used[y]==True:
continue
v[y]-=2
if v[y]<=0:
used[y]=True
S.append(y)
result=len(h)
for i in range(N):
if used[i]==False:
result+=1
break
print(result)
ゼット