結果

問題 No.1507 Road Blocked
ユーザー shiomusubi496shiomusubi496
提出日時 2021-05-14 22:23:55
言語 C++17
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 637 bytes
コンパイル時間 1,831 ms
使用メモリ 13,532 KB
最終ジャッジ日時 2022-11-25 19:16:18
合計ジャッジ時間 5,773 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 3 ms
5,900 KB
testcase_01 AC 3 ms
6,948 KB
testcase_02 AC 3 ms
5,768 KB
testcase_03 AC 63 ms
13,532 KB
testcase_04 AC 80 ms
9,492 KB
testcase_05 AC 79 ms
9,412 KB
testcase_06 AC 78 ms
9,368 KB
testcase_07 AC 83 ms
9,360 KB
testcase_08 AC 81 ms
9,468 KB
testcase_09 AC 78 ms
9,432 KB
testcase_10 AC 78 ms
9,364 KB
testcase_11 AC 75 ms
9,432 KB
testcase_12 AC 77 ms
9,360 KB
testcase_13 AC 82 ms
9,524 KB
testcase_14 AC 84 ms
9,488 KB
testcase_15 AC 69 ms
9,376 KB
testcase_16 AC 74 ms
9,368 KB
testcase_17 AC 86 ms
9,364 KB
testcase_18 AC 80 ms
9,360 KB
testcase_19 AC 83 ms
9,472 KB
testcase_20 AC 75 ms
9,440 KB
testcase_21 AC 76 ms
9,428 KB
testcase_22 AC 72 ms
9,376 KB
testcase_23 AC 73 ms
9,376 KB
testcase_24 AC 72 ms
9,372 KB
testcase_25 AC 73 ms
9,496 KB
testcase_26 AC 81 ms
9,516 KB
testcase_27 AC 82 ms
9,448 KB
testcase_28 AC 85 ms
9,468 KB
testcase_29 AC 79 ms
9,448 KB
testcase_30 AC 72 ms
9,420 KB
testcase_31 AC 85 ms
9,516 KB
testcase_32 AC 78 ms
9,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=998244353;
int N,ans;
vector<int>G[100010];
int dfs(int v,int p){
    int sum=1;
    for(int t:G[v]) if(t!=p){
        sum+=dfs(t,v);
    }
    (ans+=sum*(N-sum))%=mod;
    return sum;
}
int mod_pow(int a,int b){
  if(!b)return 1;
  if(b&1)return mod_pow(a,b-1)*a%mod;
  int c=mod_pow(a,b/2);
  return c*c%mod;
}
signed main(){
    cin>>N;
    for(int i=0;i<N-1;i++){
        int a,b; cin>>a>>b;
        G[--a].push_back(--b);
        G[b].push_back(a);
    }
    dfs(0,-1);
    cout<<(1+mod-ans*mod_pow(N*(N-1)/2%mod*(N-1)%mod,mod-2)%mod)%mod<<endl;
}
0