結果
| 問題 |
No.2677 Minmax Independent Set
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-03-15 22:28:15 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 824 bytes |
| コンパイル時間 | 254 ms |
| コンパイル使用メモリ | 82,888 KB |
| 実行使用メモリ | 123,352 KB |
| 最終ジャッジ日時 | 2024-09-30 01:53:33 |
| 合計ジャッジ時間 | 18,462 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 WA * 39 |
ソースコード
import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random
#sys.setrecursionlimit(10**9)
#sys.set_int_max_str_digits(0)
input = sys.stdin.readline
#n = int(input())
#
#s = input()
n = int(input())
edge = [[] for i in range(n)]
for i in range(n-1):
u,v = map(int,input().split())
u-=1
v-=1
edge[u].append(v)
edge[v].append(u)
color = [0 for i in range(n)]
start = 0
d = collections.deque()
dist = [10**18 for i in range(n)]
d.append(start)
dist[start] = 0
while d:
now = d.popleft()
for i in edge[now]:
if dist[i] > dist[now] + 1:
color[i] = color[now] ^ 1
dist[i] = dist[now] + 1
d.append(i)
x = sum(1 if color[i] == 0 else 0 for i in range(n))
y = sum(1 if color[i] == 1 else 0 for i in range(n))
print(min(x,y))