結果
問題 | No.2888 Mamehinata |
ユーザー |
|
提出日時 | 2024-11-15 16:34:01 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 489 ms / 2,000 ms |
コード長 | 747 bytes |
コンパイル時間 | 236 ms |
コンパイル使用メモリ | 82,196 KB |
実行使用メモリ | 120,148 KB |
最終ジャッジ日時 | 2024-11-15 16:34:21 |
合計ジャッジ時間 | 15,372 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 52 |
ソースコード
from collections import deque N, M = map(int,input().split()) G = [list() for i in range(N+1)] for i in range(M): u, v = map(int,input().split()) G[u].append(v) G[v].append(u) d = [-1]*(N+1) d[1] = 0 dist = [0]*(N+1) dist[0] += 1 Q = deque() Q.append(1) while len(Q) >= 1: x = Q.popleft() for nex in G[x]: if d[nex] == -1: d[nex] = d[x] + 1 dist[d[nex]] += 1 Q.append(nex) ans = [0] for i in range(1,N+1): if i % 2 == 1: if i == 1: ans.append(dist[i]) else: ans.append(ans[i-2] + dist[i]) else: if i == 2: if len(G[1]) == 0: ans.append(dist[i]) else: ans.append(dist[i] + dist[0]) else: ans.append(ans[i-2] + dist[i]) for i in range(1,N+1): print(ans[i])