結果

問題 No.1507 Road Blocked
ユーザー どららどらら
提出日時 2021-05-14 23:23:09
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 1,091 bytes
コンパイル時間 3,238 ms
使用メモリ 21,620 KB
最終ジャッジ日時 2022-11-25 22:31:17
合計ジャッジ時間 7,491 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 3 ms
5,760 KB
testcase_01 AC 3 ms
5,828 KB
testcase_02 AC 3 ms
5,772 KB
testcase_03 AC 75 ms
21,620 KB
testcase_04 AC 80 ms
10,752 KB
testcase_05 AC 83 ms
10,732 KB
testcase_06 AC 82 ms
10,820 KB
testcase_07 AC 87 ms
10,688 KB
testcase_08 AC 84 ms
10,816 KB
testcase_09 AC 84 ms
10,768 KB
testcase_10 AC 84 ms
10,720 KB
testcase_11 AC 82 ms
10,688 KB
testcase_12 AC 89 ms
10,728 KB
testcase_13 AC 89 ms
10,740 KB
testcase_14 AC 90 ms
10,808 KB
testcase_15 AC 82 ms
10,804 KB
testcase_16 AC 83 ms
10,796 KB
testcase_17 AC 82 ms
10,744 KB
testcase_18 AC 82 ms
10,684 KB
testcase_19 AC 82 ms
10,768 KB
testcase_20 AC 86 ms
10,688 KB
testcase_21 AC 81 ms
10,740 KB
testcase_22 AC 84 ms
10,804 KB
testcase_23 AC 83 ms
10,748 KB
testcase_24 AC 86 ms
10,756 KB
testcase_25 AC 85 ms
10,764 KB
testcase_26 AC 86 ms
10,684 KB
testcase_27 AC 82 ms
10,748 KB
testcase_28 AC 83 ms
10,768 KB
testcase_29 AC 83 ms
10,744 KB
testcase_30 AC 82 ms
10,688 KB
testcase_31 AC 79 ms
10,728 KB
testcase_32 AC 83 ms
10,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;
//using mint = modint1000000007;
using mint = modint998244353;

int N;
vector<int> G[100005];
vector<pair<ll,ll>> edges;

int dfs(int v, int p){
  int ret = 1;
  rep(i,G[v].size()){
    if(G[v][i] == p) continue;
    ll res = dfs(G[v][i], v);

    edges.emplace_back(res, N-res);

    ret += res;
  }
  
  return ret;
}
  
int main(){
  cin >> N;
  rep(i,N-1){
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  
  dfs(0,-1);

  mint ret1(0), ret2(1);
  ret2 *= N*(ll)(N-1)/2;
  ret2 *= (N-1);
  rep(i,edges.size()){
    ll x = edges[i].first;
    ll y = edges[i].second;
    
    ret1 += x*(x-1)/2 + y*(y-1)/2;
  }

  mint ret = ret1 / ret2;

  cout << ret.val() << endl;
  
  return 0;
}

0