QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#345408 | #4433. Kitten and Roomba | jiamengtong | ML | 0ms | 0kb | C++14 | 780b | 2024-03-06 21:58:28 | 2024-03-06 21:58:29 |
answer
#include<bits/stdc++.h>
#define M 1000005
using namespace std;
int n, c, fa[M];
double tg[M], ori[M], gt[M];
vector<int> v[M];
void dfs(int x, int ft)
{
fa[x] = ft;
for(auto &t : v[x])
{
if(t == ft) continue;
dfs(t, x);
}
}
void solve()
{
scanf("%d%d", &n, &c);
for(int i = 1, x, y; i < n; i++) scanf("%d%d", &x, &y), v[x].push_back(y), v[y].push_back(x);
dfs(1, 0);
ori[c] = 1;
int m;
scanf("%d", &m);
double ans = 0;
for(int i = 1, x; i <= m; i++)
{
scanf("%d", &x);
double nw = ori[x] + tg[fa[x]] - gt[x];
gt[x] = tg[fa[x]];
ori[x] = 0;
ans += nw;
nw /= v[x].size();
ori[fa[x]] += nw;
tg[x] += nw;
}
printf("%.10lf", ans);
}
int main()
{
int T;
scanf("%d", &T);
while(T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Memory 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...