結果

問題 No.1614 Majority Painting on Tree
ユーザー chocoruskchocorusk
提出日時 2021-07-21 22:19:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3,215 ms / 5,000 ms
コード長 1,914 bytes
コンパイル時間 3,405 ms
コンパイル使用メモリ 188,864 KB
実行使用メモリ 120,092 KB
最終ジャッジ日時 2023-09-24 18:26:26
合計ジャッジ時間 57,261 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,310 ms
119,872 KB
testcase_01 AC 775 ms
119,816 KB
testcase_02 AC 1,047 ms
119,792 KB
testcase_03 AC 1,804 ms
119,828 KB
testcase_04 AC 2,247 ms
119,796 KB
testcase_05 AC 2,138 ms
120,080 KB
testcase_06 AC 3,215 ms
119,800 KB
testcase_07 AC 2,281 ms
119,968 KB
testcase_08 AC 1,111 ms
119,796 KB
testcase_09 AC 1,617 ms
119,816 KB
testcase_10 AC 481 ms
119,852 KB
testcase_11 AC 2,002 ms
119,880 KB
testcase_12 AC 2,223 ms
119,824 KB
testcase_13 AC 1,607 ms
119,880 KB
testcase_14 AC 3,116 ms
119,824 KB
testcase_15 AC 2,970 ms
119,800 KB
testcase_16 AC 738 ms
119,888 KB
testcase_17 AC 1,404 ms
119,828 KB
testcase_18 AC 1,058 ms
119,888 KB
testcase_19 AC 465 ms
119,864 KB
testcase_20 AC 2,441 ms
119,792 KB
testcase_21 AC 2,496 ms
119,784 KB
testcase_22 AC 2,715 ms
119,880 KB
testcase_23 AC 337 ms
120,076 KB
testcase_24 AC 2,451 ms
119,956 KB
testcase_25 AC 606 ms
119,896 KB
testcase_26 AC 1,507 ms
119,796 KB
testcase_27 AC 34 ms
119,828 KB
testcase_28 AC 35 ms
119,804 KB
testcase_29 AC 34 ms
119,816 KB
testcase_30 AC 34 ms
119,868 KB
testcase_31 AC 34 ms
119,836 KB
testcase_32 AC 34 ms
119,964 KB
testcase_33 AC 34 ms
119,960 KB
testcase_34 AC 34 ms
119,824 KB
testcase_35 AC 34 ms
119,968 KB
testcase_36 AC 34 ms
120,088 KB
testcase_37 AC 33 ms
120,092 KB
testcase_38 AC 33 ms
119,800 KB
testcase_39 AC 33 ms
119,816 KB
testcase_40 AC 32 ms
119,816 KB
testcase_41 AC 32 ms
119,796 KB
testcase_42 AC 33 ms
119,956 KB
testcase_43 AC 33 ms
119,816 KB
testcase_44 AC 32 ms
119,780 KB
testcase_45 AC 33 ms
119,868 KB
testcase_46 AC 33 ms
119,800 KB
testcase_47 AC 33 ms
119,968 KB
testcase_48 AC 34 ms
119,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
using mint=modint998244353;
mint f[2000010], invf[2000010];
void fac(int n){
    f[0]=1;
    for(ll i=1; i<=n; i++) f[i]=f[i-1]*i;
    invf[n]=f[n].inv();
    for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1);
}
mint comb(int x, int y){
    if(!(0<=y && y<=x)) return 0;
    return f[x]*invf[y]*invf[x-y];
}
int n;
//vector<int> g[100010];
int c;
int deg[100010];
mint x[(1<<8)+1][100010];
int main()
{
    cin>>n>>c;
    fac(n);
    for(int i=0; i<n-1; i++){
        int a, b;
        cin>>a>>b;
        a--; b--;
        deg[a]++;
        deg[b]++;
    }
    for(int i=1; i<n; i++) x[1][i]=0;
    for(int i=2; i<=c; i++){
        x[i][1]=0;
        for(int j=2; j<n; j++){
            x[i][j]=(x[i][j-1]+1)*i-1;
            if(j&1){
                x[i][j]-=comb(j-1, j/2+1)*(mint(i-1).pow(j/2));
                x[i][j]+=comb(j, j/2+1)*(mint(i-1).pow(j/2));
            }else{
                x[i][j]-=comb(j-1, j/2)*(mint(i-1).pow(j/2));
            }
        }
    }
    mint ans=0;
    for(int i=c; i>=1; i--){
        mint v=1;
        for(int j=0; j<n; j++){
            if(deg[j]==1) continue;
            int d=deg[j];
            v*=(mint(i).pow(d-1)-x[i][d]);
        }
        v*=i;
        if((c-i)&1) ans-=v*comb(c, i);
        else ans+=v*comb(c, i);
    }
    cout<<ans.val()<<endl;
    return 0;
}
0