結果

問題 No.1507 Road Blocked
ユーザー shiomusubi496shiomusubi496
提出日時 2021-05-14 22:23:55
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 98 ms / 2,000 ms
コード長 637 bytes
コンパイル時間 2,160 ms
コンパイル使用メモリ 198,736 KB
実行使用メモリ 13,696 KB
最終ジャッジ日時 2024-04-10 00:53:36
合計ジャッジ時間 6,309 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,812 KB
testcase_01 AC 3 ms
6,944 KB
testcase_02 AC 3 ms
6,944 KB
testcase_03 AC 72 ms
13,696 KB
testcase_04 AC 88 ms
9,476 KB
testcase_05 AC 91 ms
9,484 KB
testcase_06 AC 93 ms
9,432 KB
testcase_07 AC 96 ms
9,600 KB
testcase_08 AC 93 ms
9,600 KB
testcase_09 AC 88 ms
9,600 KB
testcase_10 AC 92 ms
9,600 KB
testcase_11 AC 90 ms
9,600 KB
testcase_12 AC 98 ms
9,472 KB
testcase_13 AC 94 ms
9,600 KB
testcase_14 AC 98 ms
9,472 KB
testcase_15 AC 95 ms
9,472 KB
testcase_16 AC 91 ms
9,600 KB
testcase_17 AC 87 ms
9,472 KB
testcase_18 AC 86 ms
9,600 KB
testcase_19 AC 89 ms
9,472 KB
testcase_20 AC 96 ms
9,472 KB
testcase_21 AC 91 ms
9,472 KB
testcase_22 AC 92 ms
9,600 KB
testcase_23 AC 88 ms
9,600 KB
testcase_24 AC 89 ms
9,600 KB
testcase_25 AC 91 ms
9,600 KB
testcase_26 AC 94 ms
9,600 KB
testcase_27 AC 91 ms
9,728 KB
testcase_28 AC 93 ms
9,600 KB
testcase_29 AC 95 ms
9,600 KB
testcase_30 AC 90 ms
9,600 KB
testcase_31 AC 93 ms
9,600 KB
testcase_32 AC 97 ms
9,600 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