結果

問題 No.1507 Road Blocked
ユーザー HaaHaa
提出日時 2021-05-14 22:40:39
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 899 bytes
コンパイル時間 1,204 ms
使用メモリ 15,496 KB
最終ジャッジ日時 2022-11-25 19:54:58
合計ジャッジ時間 4,888 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 4 ms
7,644 KB
testcase_01 AC 4 ms
7,648 KB
testcase_02 AC 3 ms
7,744 KB
testcase_03 AC 56 ms
15,496 KB
testcase_04 AC 64 ms
11,424 KB
testcase_05 AC 64 ms
11,492 KB
testcase_06 AC 64 ms
11,464 KB
testcase_07 AC 66 ms
11,220 KB
testcase_08 AC 63 ms
11,480 KB
testcase_09 AC 63 ms
11,480 KB
testcase_10 AC 64 ms
11,420 KB
testcase_11 AC 64 ms
11,528 KB
testcase_12 AC 64 ms
11,476 KB
testcase_13 AC 63 ms
11,360 KB
testcase_14 AC 64 ms
11,376 KB
testcase_15 AC 63 ms
11,532 KB
testcase_16 AC 65 ms
11,224 KB
testcase_17 AC 66 ms
11,220 KB
testcase_18 AC 64 ms
11,464 KB
testcase_19 AC 64 ms
11,416 KB
testcase_20 AC 64 ms
11,468 KB
testcase_21 AC 65 ms
11,292 KB
testcase_22 AC 64 ms
11,480 KB
testcase_23 AC 66 ms
11,460 KB
testcase_24 AC 66 ms
11,492 KB
testcase_25 AC 63 ms
11,468 KB
testcase_26 AC 65 ms
11,464 KB
testcase_27 AC 64 ms
11,488 KB
testcase_28 AC 66 ms
11,420 KB
testcase_29 AC 65 ms
11,460 KB
testcase_30 AC 65 ms
11,560 KB
testcase_31 AC 64 ms
11,348 KB
testcase_32 AC 65 ms
11,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
constexpr ll MOD=998244353;
constexpr ll INF=2e18;

ll n;
ll x=0, y=0;
VVI g(200000);

int dfs(int v, int p){
    int sum=1;
    for(auto to:g[v]){
        if(to!=p){
            ll r=dfs(to,v);
            x-=r*(n-r)*2;
            sum+=r;
        }
    }
    return sum;
}

ll power(ll x, ll y){
    x%=MOD;
    ll ret=1;
    while(y){
        if(y&1) ret=ret*x%MOD;
        x=x*x%MOD;
        y>>=1;
    }
    return ret;
}

int main(){
    cin >> n;
    int a, b;
    REP(i,n-1){
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    y=n*(n-1)*(n-1);
    x=y;
    dfs(0,-1);
    x%=MOD;
    cout << x*power(y,MOD-2)%MOD << endl;
}
0