結果
| 問題 |
No.758 VVVVV
|
| コンテスト | |
| ユーザー |
nasadigital
|
| 提出日時 | 2018-12-08 10:03:54 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 25 ms / 2,000 ms |
| コード長 | 1,978 bytes |
| コンパイル時間 | 938 ms |
| コンパイル使用メモリ | 110,916 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-14 01:46:23 |
| 合計ジャッジ時間 | 2,103 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
#include <algorithm>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <istream>
#include <map>
#include <numeric>
#include <ostream>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define MOD 1000000007
long long comb(int n, int k, int mo);
long long fast_pow(long long a, int n, int mo = 0);
using namespace std;
class Solution {
public:
void solve(std::istream& in, std::ostream& out) {
int n;
in >> n;
int ar[n];
memset(ar, 0, sizeof(ar));
int a, b;
for (int ctr1 = 1; ctr1 < n; ++ctr1)
in >> a >> b, ++ar[a - 1], ++ar[b - 1];
int m = 0;
for (int ctr1 = 1; ctr1 < n; ++ctr1)
m += ar[ctr1] == 1;
if (n == 1) {
out << 1;
return;
}
out << ((comb(n - 1, m, MOD) * comb(n - 1, m - 1, MOD) % MOD) *
fast_pow(n - 1, MOD - 2, MOD)) % MOD;
}
};
void solve(std::istream& in, std::ostream& out)
{
out << std::setprecision(12);
Solution solution;
solution.solve(in, out);
}
// Powered by caide (code generator, tester, and library code inliner)
#include <fstream>
#include <iostream>
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
istream& in = cin;
ostream& out = cout;
solve(in, out);
return 0;
}
long long comb(int n, int k, int mo) {
if (n - k < k)
k = n - k;
int inv[k + 1];
inv[0] = inv[1] = 1;
for (long long ctr1 = 2; ctr1 <= k; ++ctr1)
inv[ctr1] = inv[mo % ctr1] * (mo - mo / ctr1) % mo;
long long rez = 1;
for (int ctr1 = 2; ctr1 <= k; ++ctr1)
rez = (rez * inv[ctr1]) % mo;
for (int ctr1 = 0; ctr1 < k; ++ctr1)
rez = (rez * (n - ctr1)) % mo;
return rez;
}
long long fast_pow(long long a, int n, int mo) {
if (n == 0)
return 1;
if (mo == 0)
return ((n & 1) ? a : 1) * fast_pow(a * a, n >> 1, mo);
return (((n & 1) ? a : 1) * fast_pow((a * a) % mo, n >> 1, mo)) % mo;
}
nasadigital