結果

問題 No.1507 Road Blocked
ユーザー 👑 NachiaNachia
提出日時 2021-05-14 22:20:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 973 bytes
コンパイル時間 1,158 ms
コンパイル使用メモリ 85,784 KB
実行使用メモリ 10,236 KB
最終ジャッジ日時 2024-04-10 00:45:14
合計ジャッジ時間 3,695 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 35 ms
10,184 KB
testcase_04 AC 50 ms
9,980 KB
testcase_05 AC 52 ms
10,100 KB
testcase_06 AC 48 ms
10,100 KB
testcase_07 AC 50 ms
10,232 KB
testcase_08 AC 49 ms
10,236 KB
testcase_09 AC 46 ms
10,108 KB
testcase_10 AC 47 ms
10,232 KB
testcase_11 AC 48 ms
10,228 KB
testcase_12 AC 48 ms
10,100 KB
testcase_13 AC 48 ms
10,100 KB
testcase_14 AC 46 ms
10,108 KB
testcase_15 AC 47 ms
10,104 KB
testcase_16 AC 47 ms
10,100 KB
testcase_17 AC 49 ms
9,980 KB
testcase_18 AC 47 ms
10,108 KB
testcase_19 AC 47 ms
10,104 KB
testcase_20 AC 48 ms
9,976 KB
testcase_21 AC 45 ms
10,108 KB
testcase_22 AC 48 ms
9,972 KB
testcase_23 AC 48 ms
10,228 KB
testcase_24 AC 48 ms
10,228 KB
testcase_25 AC 48 ms
9,976 KB
testcase_26 AC 45 ms
10,104 KB
testcase_27 AC 46 ms
10,108 KB
testcase_28 AC 48 ms
10,104 KB
testcase_29 AC 47 ms
9,976 KB
testcase_30 AC 47 ms
10,232 KB
testcase_31 AC 49 ms
9,976 KB
testcase_32 AC 47 ms
10,100 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <atcoder/modint>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using mll = atcoder::static_modint<998244353>;
#define rep(i,n) for(int i=0; i<(n); i++)


int main(){
  int N; cin >> N;
  vector<vector<int>> E(N);
  rep(i,N-1){
    int u,v; cin >> u >> v; u--; v--;
    E[u].push_back(v);
    E[v].push_back(u);
  }
  vector<int> I = {0};
  vector<int> P(N,-1);
  for(int i=0; i<I.size(); i++){
    int p = I[i];
    for(int e : E[p]) if(P[p] != e){
      P[e] = p;
      I.push_back(e);
    }
  }
  vector<int> Z(N,1);
  for(int i=N-1; i>=1; i--) Z[P[I[i]]] += Z[I[i]];

  mll ans = 0;
  for(int i=1; i<N; i++) ans += mll(Z[i]) * mll(N-Z[i]);
  ans = ans / N / (N-1) / (N-1) * 2;
  ans = 1 - ans;
  cout << ans.val() << "\n";
  return 0;
}


struct ios_do_not_sync{
  ios_do_not_sync(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  }
} ios_do_not_sync_instance;

0