結果

問題 No.758 VVVVV
ユーザー 0w10w1
提出日時 2018-12-10 02:22:01
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 1,138 bytes
コンパイル時間 1,983 ms
コンパイル使用メモリ 196,976 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 03:01:26
合計ジャッジ時間 3,115 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 21 ms
5,376 KB
testcase_04 AC 11 ms
5,376 KB
testcase_05 AC 8 ms
5,376 KB
testcase_06 AC 8 ms
5,376 KB
testcase_07 AC 21 ms
5,376 KB
testcase_08 AC 12 ms
5,376 KB
testcase_09 AC 6 ms
5,376 KB
testcase_10 AC 8 ms
5,376 KB
testcase_11 AC 21 ms
5,376 KB
testcase_12 AC 7 ms
5,376 KB
testcase_13 AC 8 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 5 ms
5,376 KB
testcase_16 AC 4 ms
5,376 KB
testcase_17 AC 19 ms
5,376 KB
testcase_18 AC 10 ms
5,376 KB
testcase_19 AC 22 ms
5,376 KB
testcase_20 AC 8 ms
5,376 KB
testcase_21 AC 8 ms
5,376 KB
testcase_22 AC 22 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 2 ms
5,376 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;
  if (N == 1) cout << 1 << endl, exit(0);

  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