QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#202251 | #4433. Kitten and Roomba | Forever_Young# | TL | 0ms | 0kb | C++14 | 781b | 2023-10-05 21:07:36 | 2023-10-05 21:07:36 |
answer
#include<bits/stdc++.h>
using namespace std;
typedef long double D;
#define pb push_back
const int N = 1000011;
vector<int> e[N];
D dp[N];
int q[50000055];
void solve() {
int n, c;
scanf("%d%d", &n, &c);
for(int i = 1; i < n; i++) {
int x, y;
scanf("%d%d", &x, &y);
e[x].pb(y);
e[y].pb(x);
}
int Q;
scanf("%d", &Q);
for(int i = 1; i <= Q; i++) {
scanf("%d", &q[i]);
}
for(int i = 1; i <= n; i++) {
dp[i] = 0;
}
for(int i = Q; i >= 1; i--) {
int v = q[i];
dp[v] = 1;
for(int y : e[v]) {
dp[v] += 1. / (D)(e[v].size()) * dp[y];
}
}
printf("%.12f\n", (double)dp[c]);
for(int i = 1; i <= n; i++) {
e[i].clear();
}
}
int main() {
int t;
scanf("%d", &t);
for(int i = 0; i < t; i++) {
solve();
}
}
详细
Test #1:
score: 0
Time Limit Exceeded
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...