結果

問題 No.2531 Coloring Vertices on Namori
ユーザー ニックネームニックネーム
提出日時 2023-11-03 23:11:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,292 ms / 2,000 ms
コード長 574 bytes
コンパイル時間 835 ms
コンパイル使用メモリ 11,828 KB
実行使用メモリ 90,136 KB
最終ジャッジ日時 2023-11-03 23:11:54
合計ジャッジ時間 28,301 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,028 KB
testcase_01 AC 28 ms
10,028 KB
testcase_02 AC 28 ms
10,028 KB
testcase_03 AC 29 ms
10,028 KB
testcase_04 AC 29 ms
10,028 KB
testcase_05 AC 942 ms
90,136 KB
testcase_06 AC 28 ms
10,044 KB
testcase_07 AC 933 ms
90,136 KB
testcase_08 AC 1,240 ms
90,136 KB
testcase_09 AC 1,259 ms
90,136 KB
testcase_10 AC 1,244 ms
90,132 KB
testcase_11 AC 685 ms
41,460 KB
testcase_12 AC 708 ms
41,460 KB
testcase_13 AC 692 ms
41,460 KB
testcase_14 AC 1,292 ms
90,136 KB
testcase_15 AC 1,266 ms
90,136 KB
testcase_16 AC 1,279 ms
90,136 KB
testcase_17 AC 29 ms
10,044 KB
testcase_18 AC 29 ms
10,044 KB
testcase_19 AC 29 ms
10,044 KB
testcase_20 AC 926 ms
47,716 KB
testcase_21 AC 883 ms
47,180 KB
testcase_22 AC 1,056 ms
52,144 KB
testcase_23 AC 1,000 ms
49,156 KB
testcase_24 AC 1,039 ms
51,728 KB
testcase_25 AC 965 ms
49,404 KB
testcase_26 AC 1,008 ms
49,340 KB
testcase_27 AC 985 ms
49,112 KB
testcase_28 AC 1,018 ms
50,848 KB
testcase_29 AC 1,054 ms
52,108 KB
testcase_30 AC 993 ms
51,216 KB
testcase_31 AC 990 ms
50,108 KB
testcase_32 AC 1,046 ms
51,208 KB
testcase_33 AC 1,033 ms
51,260 KB
権限があれば一括ダウンロードができます

ソースコード

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; x[v] = x[p]+1
    for c in adj[v]:
        if c==p: continue
        if f[c]: return x[v]-x[c]+1
        cnt = dfs(c,v)
        if cnt: return cnt
    return 0
f = [False]*n; x = [0]*n; cnt = 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