QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#553709 | #4433. Kitten and Roomba | wisniewskij | AC ✓ | 2548ms | 154056kb | C++20 | 1.6kb | 2024-09-08 18:40:56 | 2024-09-08 18:40:57 |
Judging History
answer
#include <bits/stdc++.h>
#define ndl '\n'
#define ll long long
#define INF 1000000007
#define st first
#define nd second
#define debug(x) cout << #x << ": " << x << ndl
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define all(x) (x).begin(), (x).end()
using namespace std;
void rob() {
int n, c; cin>>n>>c;
vector<vector<int>> G(n+1);
vector<long double> chance(n+1), lazy_propagation(n+1);
chance[c] = 1;
for(int i=0;i<n-1;i++) {
int a, b; cin>>a>>b;
G[a].push_back(b);
G[b].push_back(a);
}
vector<int> par(n+1);
function<void(int)> dfs = [&](int v) {
for(auto x:G[v]) {
if(x != par[v]) {
par[x] = v;
dfs(x);
}
}
};
dfs(1);
long double ans = 0;
function<long double(int)> full_chance = [&](int x) -> long double {
return chance[x] + (par[x] ? lazy_propagation[par[x]] : 0.0);
};
int seq; cin>>seq;
for(int i=0;i<seq;i++) {
int curr; cin>>curr;
long double curr_chance = full_chance(curr);
chance[curr] -= curr_chance;
ans += curr_chance;
lazy_propagation[curr] += curr_chance / G[curr].size();
if(par[curr]) {
chance[par[curr]] += curr_chance / G[curr].size();
}
}
cout<<ans<<'\n';
}
int main() {
cout<<setprecision(8) << fixed;
ios_base::sync_with_stdio(0); cin.tie(0);
int t;
cin>>t;
for(int i=0;i<t;i++)
rob();
}
詳細信息
Test #1:
score: 100
Accepted
time: 1602ms
memory: 99568kb
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.60941734 5.61050514
result:
ok 2 numbers
Test #2:
score: 0
Accepted
time: 439ms
memory: 3724kb
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.59738569 4999999.00000000 666788.77808037
result:
ok 3 numbers
Test #3:
score: 0
Accepted
time: 520ms
memory: 4060kb
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.47452217 2.12500000 23.95496351 0.00000000 2.50000000 3.93596262 3.10684155 5.58879252 3.10661965 1.79166667 5.55553072 0.00000000 4.86833078 3.49932872 0.00000000 3.10685192 5.67287159 5.68328477 0.00000000 3.07400049 4.26905534 3.10685336 6.26347074 12.44317537 4.34153286 3.10685357 0.00000000 3...
result:
ok 5050 numbers
Test #4:
score: 0
Accepted
time: 1616ms
memory: 98900kb
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.45264091 4.44663800
result:
ok 2 numbers
Test #5:
score: 0
Accepted
time: 1609ms
memory: 99636kb
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.83755414 4.27157640
result:
ok 2 numbers
Test #6:
score: 0
Accepted
time: 2548ms
memory: 154056kb
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.81481481 11.33209637
result:
ok 2 numbers
Extra Test:
score: 0
Extra Test Passed