QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#42343 | #4433. Kitten and Roomba | Antistar | RE | 0ms | 0kb | C++20 | 1.1kb | 2022-08-02 08:11:47 | 2022-08-02 08:11:47 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
vector<int> e[N];
int fa[N];
double f[N], g[N];
void dfs(int x, int fa) {
::fa[x] = fa;
for (auto v : e[x]) {
if (v != fa)
dfs(v, x);
}
}
void set_dpv(int x, double val) {
if (fa[x] != -1)
g[fa[x]] -= f[x];
f[x] = val;
if (fa[x] != -1)
g[fa[x]] += f[x];
};
double get_val(int u) {
double res = g[u];
if (fa[u] != -1)
res += f[fa[u]];
return res;
};
void solve() {
int n, c;
scanf("%d%d", &n, &c);
for (int i = 0; i < n - 1; i++) {
int x, y;
scanf("%d%d", &x, &y);
e[x].push_back(y);
e[y].push_back(x);
}
dfs(1, 0);
int m;
scanf("%d", &m);
vector<int> s;
for (int i = 1; i <= m; i++) {
int x;
scanf("%d", &x);
s.push_back(x);
}
for (int i = m - 1; i >= 0; i--) {
int x = s[i];
double w = get_val(x) / (double)e[x].size() + 1;
set_dpv(x, w);
}
printf("%.12lf\n", f[c]);
}
int main() {
int T;
scanf("%d", &T);
while (T--) {
solve();
}
}
详细
Test #1:
score: 0
Runtime Error
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...