結果

問題 No.2531 Coloring Vertices on Namori
ユーザー 👑 p-adicp-adic
提出日時 2023-10-24 10:19:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 479 ms / 2,000 ms
コード長 273 bytes
コンパイル時間 266 ms
コンパイル使用メモリ 82,100 KB
実行使用メモリ 148,388 KB
最終ジャッジ日時 2024-09-23 02:45:34
合計ジャッジ時間 12,683 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

J=lambda:map(int,input().split())
N,K=J()
L=range(N)
E=[0]+[set()for i in L]
for i in L:
	u,v=J()
	E[u].add(v),E[v].add(u)
l=N
for i in L:
	r=i+1
	while len(E[r])==1:
		l,j=l-1,E[r].pop()
		E[j].remove(r)
		r=j
P=998244353
print(pow(K-1,N-l+1,P)*(pow(K-1,l-1,P)+1-l%2*2)%P)
0