QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#138998 | #5781. Rainbow Trees | Zeardoe | 24 ✓ | 3ms | 6056kb | C++20 | 2.2kb | 2023-08-12 16:03:45 | 2023-08-12 16:03:46 |
Judging History
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; int k; const int mod = 1000000009;
void dfs(int u, int fa) {
int cnt = 0;
for(int v : t[u]) {
if(v == fa) continue;
int w = 0;
w += cnt; cnt ++;
if(fa != 0) {
w ++;
w += t[fa].size() - 1;
}
// cerr << u << " " << v << " " << w << endl;
cmin(w, k);
ans = (ans * (k - w)) % mod;
dfs(v, u);
}
}
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);
}
dfs(1, 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: 9
Accepted
Test #1:
score: 9
Accepted
time: 2ms
memory: 5920kb
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: 550484707 Case #3: 931146861 Case #4: 591871602 Case #5: 316604373 Case #6: 0 Case #7: 86453409 Case #8: 352074424 Case #9: 986385060 Case #10: 0 Case #11: 402448399 Case #12: 707302553 Case #13: 246873311 Case #14: 713664476 Case #15: 726754528 Case #16: 311072601 Case #17: 7470...
result:
ok 100 lines
Subtask #2:
score: 15
Accepted
Test #2:
score: 15
Accepted
time: 3ms
memory: 6056kb
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: 527618146 Case #2: 0 Case #3: 625151768 Case #4: 665582320 Case #5: 371788967 Case #6: 907602762 Case #7: 0 Case #8: 0 Case #9: 441406118 Case #10: 887678455 Case #11: 697513790 Case #12: 481386847 Case #13: 600564428 Case #14: 741272596 Case #15: 331102368 Case #16: 672531288 Case #17: 152...
result:
ok 40 lines
Extra Test:
score: 0
Extra Test Passed