QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#138870 | #5781. Rainbow Trees | Zeardoe | 0 | 3ms | 6044kb | C++20 | 2.3kb | 2023-08-12 12:24:16 | 2023-08-12 12:24:20 |
answer
/*
[templates]:
duipai
spjdp
compre
addhis
floor_sum
treedfs
matrix
*/
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
#include<bits/stdc++.h>
using namespace std;
#define int long long
//use ll instead of int.
#define f(i, a, b) for(int i = (a); i <= (b); i++)
#define cl(i, n) i.clear(),i.resize(n);
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 1e9;
//#define cerr if(false)cerr
//#define freopen if(false)freopen
mt19937 rng(time(0));
int rnd(int l, int r) {return rng() % (r-l+1) + l; }
#define watch(x) cerr << (#x) << ' '<<'i'<<'s'<<' ' << x << endl
void pofe(int number, int bitnum) {
string s; f(i, 0, bitnum) {s += char(number & 1) + '0'; number >>= 1; }
reverse(s.begin(), s.end()); cerr << s << endl;
return;
}
template <typename TYP> void cmax(TYP &x, TYP y) {if(x < y) x = y;}
template <typename TYP> void cmin(TYP &x, TYP y) {if(x > y) x = y;}
//调不出来给我对拍!
//use std::array.
vector<int> t[100100]; int ans = 1, leaf, root; int k; const int mod = 1000000009;
void dfs(int now, int fa, int un) {
if(fa != 0) un ++;
if(fa != 0 && fa != root) un ++;
// cerr << now << " " << fa << " " << un << endl;
ans *= k - un;
ans %= mod;
int cnt = 0;
for(int i : t[now]) {
if(i != fa && i != leaf) {
dfs(i, now, cnt++);
}
}
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
//freopen();
//freopen();
//time_t start = clock();
//think twice,code once.
//think once,debug forever.
int T; cin >> T; int TT = 0;
while(T--) {
TT ++;
int n; cin >> n; cin >> k; ans = 1;
f(i, 1, n) t[i].clear();
f(i, 1, n - 1) {
int u, v; cin >> u >> v;
t[u].push_back(v); t[v].push_back(u);
}
f(i, 1, n) if(t[i].size() == 1) leaf = i;
root = t[leaf][0];
// cerr << root << " " << leaf << endl;
dfs(root, 0, 0);
cout << "Case #" << TT << ": " << ans << endl;
}
//time_t finish = clock();
//cout << "time used:" << (finish-start) * 1.0 / CLOCKS_PER_SEC <<"s"<< endl;
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 6020kb
input:
100 5 3 2 5 2 1 4 5 4 3 18 12 6 12 6 3 12 7 3 17 7 13 17 2 13 10 2 15 2 9 10 18 10 11 15 4 15 1 9 8 9 5 9 16 9 14 17 735708 5 11 5 13 5 9 5 8 5 2 5 1 5 10 5 17 5 4 5 6 5 3 5 14 5 16 5 15 5 12 5 7 18 923537 8 5 8 3 8 15 8 12 5 17 5 14 5 4 5 18 5 11 5 13 5 16 3 10 3 1 3 7 3 2 3 6 15 9 19 999946814 7 1...
output:
Case #1: 6 Case #2: 515010889 Case #3: 931146861 Case #4: 485445597 Case #5: 892404806 Case #6: 44952664 Case #7: 835310815 Case #8: 686276683 Case #9: 63352000 Case #10: 0 Case #11: 422724880 Case #12: 173734704 Case #13: 246873311 Case #14: 556253936 Case #15: 298122368 Case #16: 368897692 Case #1...
result:
wrong answer 2nd lines differ - expected: 'Case #2: 550484707', found: 'Case #2: 515010889'
Subtask #2:
score: 0
Wrong Answer
Test #2:
score: 0
Wrong Answer
time: 3ms
memory: 6044kb
input:
40 208 591433 87 116 87 88 116 119 88 59 119 56 119 51 119 16 119 90 119 188 119 126 119 55 119 190 119 139 59 43 59 174 56 128 56 44 51 57 16 69 16 171 16 204 16 111 90 11 90 202 90 147 188 24 126 25 126 54 55 73 55 37 55 97 55 164 190 83 139 198 139 133 43 3 43 46 174 156 128 161 128 68 128 35 128...
output:
Case #1: 261673769 Case #2: 0 Case #3: 380803279 Case #4: 301836901 Case #5: 50944152 Case #6: 873948524 Case #7: 957784251 Case #8: 0 Case #9: 592335468 Case #10: 385958587 Case #11: 217351481 Case #12: 45549597 Case #13: 532638270 Case #14: 72460493 Case #15: 326021775 Case #16: 164786185 Case #17...
result:
wrong answer 1st lines differ - expected: 'Case #1: 527618146', found: 'Case #1: 261673769'