結果

問題 No.1507 Road Blocked
ユーザー umezoumezo
提出日時 2021-05-14 23:27:20
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 832 bytes
コンパイル時間 2,212 ms
コンパイル使用メモリ 199,540 KB
実行使用メモリ 13,696 KB
最終ジャッジ日時 2024-04-10 03:54:15
合計ジャッジ時間 5,697 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 3 ms
6,944 KB
testcase_03 AC 73 ms
13,696 KB
testcase_04 AC 77 ms
9,856 KB
testcase_05 AC 77 ms
9,856 KB
testcase_06 AC 82 ms
9,984 KB
testcase_07 AC 83 ms
9,892 KB
testcase_08 AC 78 ms
9,948 KB
testcase_09 AC 78 ms
9,740 KB
testcase_10 AC 80 ms
9,856 KB
testcase_11 AC 99 ms
9,888 KB
testcase_12 AC 77 ms
9,800 KB
testcase_13 AC 78 ms
9,856 KB
testcase_14 AC 76 ms
9,840 KB
testcase_15 AC 79 ms
9,856 KB
testcase_16 AC 81 ms
9,928 KB
testcase_17 AC 79 ms
9,856 KB
testcase_18 AC 77 ms
9,796 KB
testcase_19 AC 81 ms
9,844 KB
testcase_20 AC 78 ms
9,792 KB
testcase_21 AC 78 ms
9,924 KB
testcase_22 AC 75 ms
9,796 KB
testcase_23 AC 77 ms
9,800 KB
testcase_24 AC 80 ms
9,728 KB
testcase_25 AC 79 ms
9,856 KB
testcase_26 AC 83 ms
9,728 KB
testcase_27 AC 78 ms
9,800 KB
testcase_28 AC 79 ms
9,924 KB
testcase_29 AC 79 ms
9,728 KB
testcase_30 AC 83 ms
9,920 KB
testcase_31 AC 79 ms
9,796 KB
testcase_32 AC 78 ms
9,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

vector<int> G[100010];
const ll MOD=998244353;

ll modinv(ll a,ll m){
  ll b=m,u=1,v=0;
  while(b){
    ll t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  u%=m; 
  if(u<0) u+=m;
  return u;
}

ll A[100010];

ll dfs(int v,int pa){
  ll cnt=1;
  for(auto nv:G[v]){
    if(nv==pa) continue;
    cnt+=dfs(nv,v);
  }
  return A[v]=cnt;
}

int main(){
  ll n;
  cin>>n;
  rep(i,n-1){
    int u,v;
    cin>>u>>v;
    u--,v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  
  dfs(0,-1);
  
  ll sum=n*(n-1)/2*(n-1);
  ll tmp=0;
  rep(i,n) tmp+=A[i]*(n-A[i]);
  ll p=sum-tmp,q=sum;
  ll g=gcd(p,q);
  p/=g,q/=g;
  cout<<p%MOD*modinv(q,MOD)%MOD<<endl;
  
  return 0;
}
0