結果

問題 No.994 ばらばらコイン
ユーザー 👑 timitimi
提出日時 2021-01-05 09:51:20
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 434 ms / 2,000 ms
コード長 608 bytes
コンパイル時間 91 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 17,920 KB
最終ジャッジ日時 2024-04-23 16:11:21
合計ジャッジ時間 5,770 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,880 KB
testcase_01 AC 29 ms
10,624 KB
testcase_02 AC 396 ms
17,920 KB
testcase_03 AC 428 ms
17,920 KB
testcase_04 AC 416 ms
17,792 KB
testcase_05 AC 228 ms
14,464 KB
testcase_06 AC 434 ms
17,920 KB
testcase_07 AC 423 ms
17,920 KB
testcase_08 AC 293 ms
15,744 KB
testcase_09 AC 406 ms
17,536 KB
testcase_10 AC 286 ms
15,616 KB
testcase_11 AC 328 ms
16,256 KB
testcase_12 AC 362 ms
16,768 KB
testcase_13 AC 29 ms
10,752 KB
testcase_14 AC 29 ms
10,752 KB
testcase_15 AC 29 ms
10,880 KB
testcase_16 AC 30 ms
10,752 KB
testcase_17 AC 30 ms
10,752 KB
testcase_18 AC 31 ms
10,752 KB
testcase_19 AC 29 ms
10,752 KB
testcase_20 AC 30 ms
10,752 KB
testcase_21 AC 29 ms
10,752 KB
testcase_22 AC 29 ms
10,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,K=map(int,input().split())  
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(N-1):
  a,b=map(int,input().split())
  a-=1
  b-=1
  union(a,b)
a=(size[find(0)])
if a<K:
  print(-1)
else:
  print(K-1)
0