結果

問題 No.2531 Coloring Vertices on Namori
ユーザー sasa8uyauyasasa8uyauya
提出日時 2023-11-04 01:17:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 576 ms / 2,000 ms
コード長 485 bytes
コンパイル時間 432 ms
コンパイル使用メモリ 81,792 KB
実行使用メモリ 143,488 KB
最終ジャッジ日時 2023-11-04 01:17:20
合計ジャッジ時間 15,087 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,564 KB
testcase_01 AC 36 ms
53,564 KB
testcase_02 AC 37 ms
53,564 KB
testcase_03 AC 36 ms
53,564 KB
testcase_04 AC 37 ms
53,564 KB
testcase_05 AC 248 ms
124,768 KB
testcase_06 AC 36 ms
53,568 KB
testcase_07 AC 243 ms
124,768 KB
testcase_08 AC 431 ms
134,928 KB
testcase_09 AC 395 ms
134,928 KB
testcase_10 AC 394 ms
134,932 KB
testcase_11 AC 259 ms
143,488 KB
testcase_12 AC 262 ms
143,488 KB
testcase_13 AC 260 ms
143,360 KB
testcase_14 AC 346 ms
127,300 KB
testcase_15 AC 346 ms
127,304 KB
testcase_16 AC 370 ms
127,304 KB
testcase_17 AC 36 ms
53,568 KB
testcase_18 AC 36 ms
53,568 KB
testcase_19 AC 35 ms
53,568 KB
testcase_20 AC 468 ms
137,448 KB
testcase_21 AC 492 ms
137,436 KB
testcase_22 AC 471 ms
137,316 KB
testcase_23 AC 486 ms
137,316 KB
testcase_24 AC 576 ms
137,312 KB
testcase_25 AC 501 ms
137,460 KB
testcase_26 AC 520 ms
137,296 KB
testcase_27 AC 477 ms
137,400 KB
testcase_28 AC 471 ms
137,296 KB
testcase_29 AC 480 ms
137,460 KB
testcase_30 AC 500 ms
137,308 KB
testcase_31 AC 470 ms
137,404 KB
testcase_32 AC 493 ms
137,448 KB
testcase_33 AC 482 ms
137,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,k=map(int,input().split())
M=998244353
e=[[] for i in range(n)]
d=[0]*n
for i in range(n):
  a,b=map(int,input().split())
  a-=1
  b-=1
  e[a]+=[b]
  e[b]+=[a]
  d[a]+=1
  d[b]+=1

v=[d[i]==1 for i in range(n)]
q=[i for i in range(n) if d[i]==1]

for s in q:
  for t in e[s]:
    d[t]-=1
    if d[t]==1 and v[t]==0:
      v[t]=1
      q+=[t]

q1=[0,0]
q2=[0,k]
for i in range(2,n+2):
  q1+=[(q1[i-1]*(k-2)+q2[i-1]*(k-1))%M]
  q2+=[q1[i-1]]

l=n-sum(v)
print(q2[l+1]*pow(k-1,n-l,M)%M)
0