QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#189973 | #4433. Kitten and Roomba | berarchegas# | AC ✓ | 6837ms | 152216kb | C++17 | 1.7kb | 2023-09-28 03:33:45 | 2023-09-28 03:33:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 5;
const int INF = 1e9;
int sq, room[5 * MAXN];
double dp[MAXN], keep[MAXN];
vector<int> v[MAXN], big[MAXN];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(20) << fixed;
int t;
cin >> t;
while (t--) {
int n, m, c;
cin >> n >> c;
sq = sqrt(n);
int a, b;
for (int i = 0; i < n - 1; i++) {
cin >> a >> b;
v[a].push_back(b);
v[b].push_back(a);
}
for (int i = 1; i <= n; i++) {
for (int x : v[i]) {
if (v[x].size() > sq) big[i].push_back(x);
}
}
cin >> m;
for (int i = 0; i < m; i++) {
cin >> room[i];
}
double ans = 0;
for (int i = m - 1; i >= 0; i--) {
double ant = dp[room[i]];
double sum = keep[room[i]];
for (int x : big[room[i]]) {
sum += dp[x];
}
dp[room[i]] = 1 + sum / v[room[i]].size();
if (v[room[i]].size() <= sq) {
// big
for (int x : v[room[i]]) {
keep[x] += dp[room[i]] - ant;
}
}
if (room[i] == c) ans = dp[room[i]];
}
cout << ans << '\n';
for (int i = 1; i <= n; i++) {
dp[i] = 0;
keep[i] = 0;
v[i].clear();
big[i].clear();
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 6837ms
memory: 152212kb
input:
2 1000000 315562 969409 917725 324847 719085 524235 603427 576843 433171 75335 238378 266746 487233 80422 95099 594363 96140 858172 261406 958326 466109 233845 350950 863969 345645 689972 81395 395383 27274 93913 208983 523722 380358 108074 172341 130041 692304 737158 383812 752080 33646 154356 6672...
output:
5.60941734148671589111 5.61050513929253469314
result:
ok 2 numbers
Test #2:
score: 0
Accepted
time: 399ms
memory: 71400kb
input:
3 3 3 2 1 2 3 4000000 2 1 2 1 2 3 2 3 2 3 2 1 2 3 2 1 2 3 2 1 2 3 2 3 2 3 2 3 2 1 2 3 2 1 2 3 2 1 2 1 2 1 2 1 2 1 2 1 2 3 2 1 2 3 2 3 2 3 2 3 2 1 2 1 2 1 2 1 2 1 2 1 2 3 2 1 2 1 2 3 2 3 2 1 2 3 2 3 2 1 2 1 2 1 2 3 2 3 2 3 2 3 2 1 2 3 2 1 2 1 2 3 2 3 2 1 2 3 2 3 2 3 2 3 2 3 2 1 2 3 2 1 2 3 2 1 2 1 2 ...
output:
2000496.60210082260891795158 4999999.00000000000000000000 666788.77678084035869687796
result:
ok 3 numbers
Test #3:
score: 0
Accepted
time: 366ms
memory: 56664kb
input:
5050 178 146 7 29 45 132 140 19 48 80 50 147 24 98 176 94 45 124 3 161 36 94 4 33 24 81 94 123 4 15 12 170 152 95 55 152 24 131 94 32 121 150 37 167 146 80 65 152 99 150 24 60 8 29 5 163 64 50 93 67 19 13 24 153 80 152 29 120 67 59 138 48 5 17 19 35 94 116 57 142 80 53 6 45 29 80 150 40 47 161 62 94...
output:
3.47452217431021104233 2.12500000000000000000 23.95496350765755977363 0.00000000000000000000 2.50000000000000000000 3.93596262458774015514 3.10684154549552182800 5.58879251697119894260 3.10661964640745225097 1.79166666666666674068 5.55553071763157646501 0.00000000000000000000 4.86833077589700735643 ...
result:
ok 5050 numbers
Test #4:
score: 0
Accepted
time: 4307ms
memory: 128884kb
input:
2 1000000 315562 679816 923554 749026 119526 400361 398944 729861 38631 237682 984276 240713 304346 923009 28429 705303 35145 281546 196216 128884 76719 542097 696978 832261 79936 617939 739512 639643 738806 304260 52873 63627 552308 627252 842013 683909 619035 326617 406438 159332 82575 823300 4115...
output:
4.45264091252809457444 4.44663799685922889182
result:
ok 2 numbers
Test #5:
score: 0
Accepted
time: 5656ms
memory: 152216kb
input:
2 1000000 315562 575035 646638 803204 719085 692015 374086 755314 193304 776395 55874 976706 805712 217914 823156 919201 953003 149774 16297 569437 50630 191605 6485 126613 286636 24494 152244 160536 434534 692015 362579 892731 521828 374895 872623 583943 946248 226984 256881 130161 826314 247361 45...
output:
5.83755413654163746173 4.27157639739905192755
result:
ok 2 numbers
Test #6:
score: 0
Accepted
time: 1531ms
memory: 151912kb
input:
2 1000000 941595 260117 135833 814046 740606 747365 965295 391550 71159 728551 704248 786875 854209 980320 968654 685130 721737 464879 19066 485673 803636 761076 467129 693561 787751 69739 373415 994214 367199 13100 494671 996272 547209 992937 103917 484331 476434 493297 779246 882922 78092 622726 3...
output:
8.81481481481481665696 11.33209636637744388565
result:
ok 2 numbers
Extra Test:
score: 0
Extra Test Passed