結果

問題 No.2531 Coloring Vertices on Namori
ユーザー maksimmaksim
提出日時 2023-11-03 22:10:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 967 bytes
コンパイル時間 1,663 ms
コンパイル使用メモリ 170,344 KB
実行使用メモリ 28,744 KB
最終ジャッジ日時 2023-11-03 22:10:51
合計ジャッジ時間 6,683 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,324 KB
testcase_01 AC 4 ms
9,324 KB
testcase_02 AC 4 ms
9,328 KB
testcase_03 AC 5 ms
9,324 KB
testcase_04 AC 4 ms
9,324 KB
testcase_05 AC 70 ms
28,744 KB
testcase_06 AC 5 ms
9,324 KB
testcase_07 AC 69 ms
28,744 KB
testcase_08 AC 101 ms
28,744 KB
testcase_09 AC 101 ms
28,744 KB
testcase_10 AC 135 ms
28,744 KB
testcase_11 AC 50 ms
17,360 KB
testcase_12 AC 49 ms
17,360 KB
testcase_13 AC 48 ms
17,360 KB
testcase_14 AC 108 ms
28,744 KB
testcase_15 AC 114 ms
28,744 KB
testcase_16 AC 134 ms
28,744 KB
testcase_17 AC 4 ms
9,328 KB
testcase_18 AC 4 ms
9,328 KB
testcase_19 AC 4 ms
9,324 KB
testcase_20 AC 123 ms
17,348 KB
testcase_21 AC 141 ms
17,356 KB
testcase_22 AC 133 ms
17,340 KB
testcase_23 AC 107 ms
17,336 KB
testcase_24 AC 94 ms
17,360 KB
testcase_25 AC 122 ms
17,340 KB
testcase_26 AC 124 ms
17,320 KB
testcase_27 AC 134 ms
17,336 KB
testcase_28 AC 124 ms
17,348 KB
testcase_29 AC 131 ms
17,348 KB
testcase_30 AC 97 ms
17,376 KB
testcase_31 AC 126 ms
17,384 KB
testcase_32 AC 116 ms
17,348 KB
testcase_33 AC 133 ms
17,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#define int long long
const int p=998244353;
int po(int a,int b) {if(b==0) return 1;if(b==1) return a; if(b%2==0) {int u=po(a,b/2);return (u*u)%p;} else {int u=po(a,b-1);return (a*u)%p;}}
const int maxn=2e5+5;
vector<int> a[maxn];bool used[maxn];int corn[maxn];int cn=0;
void dfs(int x,int pr)
{
    used[x]=true;
    for(int v:a[x])
    {
        if(!used[v])
        {
            corn[v]=corn[x]+1;
            dfs(v,x);
        }
        else if(v!=pr && corn[v]<corn[x])
        {
            cn=corn[x]-corn[v]+1;
        }
    }
}
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,k;cin>>n>>k;
    for(int i=0;i<n;++i)
    {
        int x,y;cin>>x>>y;--x;--y;
        a[x].push_back(y);a[y].push_back(x);
    }
    dfs(0,-1);
    int res=po(k-1,cn);if(cn%2==0) {res+=(k-1);} else {res-=(k-1);}
    res%=p;
    res*=po(k-1,n-cn);res%=p;
    cout<<(res%p+p)%p;
    return 0;
}
0