結果

問題 No.2531 Coloring Vertices on Namori
ユーザー ニックネームニックネーム
提出日時 2023-11-03 23:00:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 563 bytes
コンパイル時間 200 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 80,824 KB
最終ジャッジ日時 2023-11-03 23:01:00
合計ジャッジ時間 23,088 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
10,160 KB
testcase_01 AC 25 ms
10,160 KB
testcase_02 AC 26 ms
10,160 KB
testcase_03 AC 24 ms
10,160 KB
testcase_04 AC 23 ms
10,160 KB
testcase_05 AC 797 ms
80,772 KB
testcase_06 AC 24 ms
10,160 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 597 ms
40,028 KB
testcase_12 AC 626 ms
40,028 KB
testcase_13 AC 597 ms
40,028 KB
testcase_14 AC 1,024 ms
80,772 KB
testcase_15 AC 1,024 ms
80,772 KB
testcase_16 AC 992 ms
80,772 KB
testcase_17 WA -
testcase_18 AC 25 ms
10,160 KB
testcase_19 AC 24 ms
10,160 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import setrecursionlimit
setrecursionlimit(10**6)
n,k = map(int,input().split())
adj = [[] for _ in range(n)]
for _ in range(n):
    u,v = map(int,input().split())
    adj[u-1].append(v-1); adj[v-1].append(u-1)
def dfs(v,p):
    f[v] = True; global cnt; cnt += 1
    for c in adj[v]:
        if c==p: continue
        if f[c]: return True
        if dfs(c,v): return True
    cnt -= 1; return False
f = [False]*n; cnt = 0; dfs(0,-1)
mod = 998244353; p,q = 0,k*(k-1)%mod
for _ in range(cnt-2): p,q = q,((k-1)*p+(k-2)*q)%mod
print(q*pow(k-1,n-cnt,mod)%mod)
0