結果

問題 No.758 VVVVV
ユーザー 0w10w1
提出日時 2018-12-10 02:21:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,096 bytes
コンパイル時間 2,469 ms
コンパイル使用メモリ 200,648 KB
実行使用メモリ 4,740 KB
最終ジャッジ日時 2023-10-14 22:01:54
合計ジャッジ時間 4,933 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 WA -
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 20 ms
4,740 KB
testcase_04 AC 10 ms
4,352 KB
testcase_05 AC 8 ms
4,348 KB
testcase_06 AC 7 ms
4,348 KB
testcase_07 AC 20 ms
4,604 KB
testcase_08 AC 12 ms
4,352 KB
testcase_09 AC 5 ms
4,348 KB
testcase_10 AC 8 ms
4,348 KB
testcase_11 AC 22 ms
4,604 KB
testcase_12 AC 6 ms
4,348 KB
testcase_13 AC 8 ms
4,352 KB
testcase_14 AC 5 ms
4,348 KB
testcase_15 AC 3 ms
4,352 KB
testcase_16 AC 4 ms
4,348 KB
testcase_17 AC 18 ms
4,348 KB
testcase_18 AC 10 ms
4,352 KB
testcase_19 AC 21 ms
4,612 KB
testcase_20 AC 7 ms
4,352 KB
testcase_21 AC 8 ms
4,352 KB
testcase_22 AC 22 ms
4,692 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 1 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int M = int(1e9 + 7);

signed main() {
  ios::sync_with_stdio(false);

  int N;
  cin >> N;

  vector<int> deg(N);
  for (int i = 0; i + 1 < N; ++i) {
    int X, Y;
    cin >> X >> Y;
    --X, --Y;
    ++deg[X], ++deg[Y];
  }

  int lcnt = count(deg.begin(), deg.end(), 1) - (deg[0] == 1);

  vector<int> fac(N);
  for (int i = fac[0] = 1; i < N; ++i) fac[i] = 1LL * fac[i - 1] * i % M;

  auto int_pow = [](int x, int e) {
    int r = 1;
    for (int i = e; i; i /= 2) {
      if (i & 1) r = 1LL * r * x % M;
      x = 1LL * x * x % M;
    }
    return r;
  };

  vector<int> ifac(N);
  ifac[N - 1] = int_pow(fac[N - 1], M - 2);
  for (int i = N - 1; i; --i) ifac[i - 1] = 1LL * ifac[i] * i % M;
  vector<int> inv(N);
  for (int i = 1; i < N; ++i) inv[i] = 1LL * ifac[i] * fac[i - 1] % M;

  int a = 1LL * fac[N - 1] * ifac[lcnt - 1] % M * ifac[N - lcnt] % M;
  int b = 1LL * fac[N - 2] * ifac[lcnt - 1] % M * ifac[N - lcnt - 1] % M;
  int ans = 1LL * a * b % M * inv[lcnt] % M;
  if (ans < 0) ans += M;
  cout << ans << endl;

  return 0;
}
0