結果
問題 | No.317 辺の追加 |
ユーザー |
![]() |
提出日時 | 2023-09-20 00:09:41 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,262 bytes |
コンパイル時間 | 158 ms |
コンパイル使用メモリ | 81,664 KB |
実行使用メモリ | 85,248 KB |
最終ジャッジ日時 | 2024-07-05 21:50:44 |
合計ジャッジ時間 | 5,607 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | TLE * 1 -- * 37 |
ソースコード
N,M=map(int,input().split())from collections import Counter# UnionFindGroup = [i for i in range(N)] # グループ分けNodes = [1]*(N) # 各グループのノードの数def find(x):while Group[x] != x:x=Group[x]return xdef Union(x,y):if find(x) != find(y):if Nodes[find(x)] < Nodes[find(y)]:Nodes[find(y)] += Nodes[find(x)]Nodes[find(x)] = 0Group[find(x)] = find(y)else:Nodes[find(x)] += Nodes[find(y)]Nodes[find(y)] = 0Group[find(y)] = find(x)for i in range(M):x,y=map(int,input().split())x-=1y-=1Union(x,y)LIST=[]for i in range(N):if find(i)==i:LIST.append(Nodes[i])C=Counter(LIST)DP=[1<<30]*(N+1)DP[0]=0for l in LIST:c=C[l]LL=[]for j in range(30):if c>2**i:LL.append(2**i)c-=2**ielse:LL.append(c)break#print(DP,LL)for x in LL:for j in range(N-x*l,-1,-1):if DP[j]!=1<<30:DP[j+x*l]=min(DP[j+x*l],DP[j]+x)#print(DP)for i in range(1,N+1):if DP[i]==1<<30:print(-1)else:print(DP[i]-1)