結果

問題 No.1507 Road Blocked
ユーザー HaaHaa
提出日時 2021-05-14 22:40:39
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 899 bytes
コンパイル時間 1,730 ms
コンパイル使用メモリ 168,012 KB
実行使用メモリ 15,780 KB
最終ジャッジ日時 2024-04-10 01:28:03
合計ジャッジ時間 5,954 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,020 KB
testcase_01 AC 4 ms
7,940 KB
testcase_02 AC 3 ms
7,864 KB
testcase_03 AC 74 ms
15,780 KB
testcase_04 AC 90 ms
11,532 KB
testcase_05 AC 95 ms
11,580 KB
testcase_06 AC 91 ms
11,572 KB
testcase_07 AC 95 ms
11,512 KB
testcase_08 AC 95 ms
11,524 KB
testcase_09 AC 94 ms
11,668 KB
testcase_10 AC 93 ms
11,592 KB
testcase_11 AC 93 ms
11,616 KB
testcase_12 AC 91 ms
11,532 KB
testcase_13 AC 92 ms
11,564 KB
testcase_14 AC 92 ms
11,532 KB
testcase_15 AC 92 ms
11,584 KB
testcase_16 AC 91 ms
11,500 KB
testcase_17 AC 94 ms
11,620 KB
testcase_18 AC 90 ms
11,512 KB
testcase_19 AC 92 ms
11,684 KB
testcase_20 AC 90 ms
11,644 KB
testcase_21 AC 92 ms
11,672 KB
testcase_22 AC 89 ms
11,528 KB
testcase_23 AC 92 ms
11,532 KB
testcase_24 AC 94 ms
11,524 KB
testcase_25 AC 94 ms
11,592 KB
testcase_26 AC 92 ms
11,508 KB
testcase_27 AC 91 ms
11,508 KB
testcase_28 AC 94 ms
11,504 KB
testcase_29 AC 95 ms
11,504 KB
testcase_30 AC 91 ms
11,512 KB
testcase_31 AC 90 ms
11,592 KB
testcase_32 AC 94 ms
11,576 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