結果

問題 No.1507 Road Blocked
ユーザー umezoumezo
提出日時 2021-05-14 22:43:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 826 bytes
コンパイル時間 2,225 ms
コンパイル使用メモリ 201,456 KB
実行使用メモリ 13,484 KB
最終ジャッジ日時 2023-07-25 08:14:55
合計ジャッジ時間 6,659 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,680 KB
testcase_01 AC 4 ms
5,836 KB
testcase_02 AC 4 ms
5,772 KB
testcase_03 AC 70 ms
13,484 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

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 p){
  ll cnt=1;
  for(auto nv:G[v]){
    if(nv==p) 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*modinv(q,MOD)%MOD<<endl;
  
  return 0;
}
0