結果

問題 No.2888 Mamehinata
ユーザー timi
提出日時 2024-09-13 21:39:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 764 ms / 2,000 ms
コード長 1,040 bytes
コンパイル時間 178 ms
コンパイル使用メモリ 82,200 KB
実行使用メモリ 114,524 KB
最終ジャッジ日時 2024-09-13 21:39:32
合計ジャッジ時間 21,213 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 52
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M=map(int,input().split())
#A=list(map(int, input().split()))
D=[[] for i in range(N)]
par=[i for i in range(N)]
rank=[0]*(N)
friend=[0]*N
block=[0]*N
size=[1]*N

def find(x):
  if par[x]==x:
    return x
  else:
    par[x]=find(par[x])
    return par[x]

#同じ集合か判定
def same(x,y):
  return find(x)==find(y)
 
def union(x,y):
  x=find(x)
  y=find(y)
  if x==y:
    return 
  if rank[x]>rank[y]:
    par[y]=x
    size[x]+=size[y]
  else:
    par[x]=y
    size[y]+=size[x]
    if rank[x]==rank[y]:
      rank[y]+=1


for i in range(M):
  x,y=map(int,input().split())
  x-=1;y-=1
  union(x,y)
  D[x].append(y);D[y].append(x)
  
from collections import deque
d=deque()
V=[-1]*N 
V[0]=0
d.append(0)
E=[0]*(N+1)
E[0]+=1
while d:
  now=d.popleft()
  for nex in D[now]:
    if V[nex]==-1:
      V[nex]=V[now]+1
      d.append(nex)
      E[V[nex]]+=1

d=find(0)
if size[d]!=1:
  p,q=1,0 
  for i in range(1,N+1):
    if i%2==1:
      q+=E[i]
      print(q)
    else:
      p+=E[i]
      print(p)
else:
  for i in range(N):
    print(0)
0