結果

問題 No.1507 Road Blocked
ユーザー どららどらら
提出日時 2021-05-14 23:23:09
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 1,091 bytes
コンパイル時間 3,994 ms
コンパイル使用メモリ 226,448 KB
実行使用メモリ 21,984 KB
最終ジャッジ日時 2024-04-10 03:42:49
合計ジャッジ時間 7,909 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,812 KB
testcase_01 AC 3 ms
6,944 KB
testcase_02 AC 4 ms
6,944 KB
testcase_03 AC 81 ms
21,984 KB
testcase_04 AC 84 ms
11,000 KB
testcase_05 AC 83 ms
11,108 KB
testcase_06 AC 84 ms
11,000 KB
testcase_07 AC 83 ms
10,992 KB
testcase_08 AC 88 ms
11,120 KB
testcase_09 AC 87 ms
11,132 KB
testcase_10 AC 84 ms
11,108 KB
testcase_11 AC 84 ms
10,988 KB
testcase_12 AC 87 ms
10,984 KB
testcase_13 AC 90 ms
10,988 KB
testcase_14 AC 90 ms
11,116 KB
testcase_15 AC 86 ms
10,996 KB
testcase_16 AC 94 ms
10,984 KB
testcase_17 AC 83 ms
11,120 KB
testcase_18 AC 83 ms
11,104 KB
testcase_19 AC 82 ms
11,120 KB
testcase_20 AC 84 ms
10,980 KB
testcase_21 AC 82 ms
11,104 KB
testcase_22 AC 78 ms
11,004 KB
testcase_23 AC 80 ms
11,120 KB
testcase_24 AC 80 ms
11,116 KB
testcase_25 AC 82 ms
10,976 KB
testcase_26 AC 83 ms
11,112 KB
testcase_27 AC 82 ms
10,980 KB
testcase_28 AC 79 ms
10,984 KB
testcase_29 AC 82 ms
10,984 KB
testcase_30 AC 80 ms
11,120 KB
testcase_31 AC 86 ms
10,988 KB
testcase_32 AC 81 ms
11,112 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