QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#100797 | #4433. Kitten and Roomba | Yanagi_Origami# | WA | 3327ms | 103080kb | C++20 | 2.2kb | 2023-04-28 09:49:16 | 2023-04-28 09:49:17 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2")
#define forn(i,a,b) for(int i=(a); (i)<(b); i++)
#define fore(i,a,b) for(int i=(a); (i)<=(b); i++)
#define pb push_back
#define sz(a) static_cast<int>((a).size())
#define F first
#define S second
constexpr int INF = 1'000'000'000;
using ll = long long;
using ld = double;
struct FT {
vector<ld> s;
FT(int n) : s(n) {}
void update0(int pos, ld dif) {
if (pos < 0 || pos >= sz(s)) return;
for (; pos < sz(s); pos |= pos + 1) s[pos] += dif;
}
void update(int l, int r, ld dif) {
if (l > r) return;
update0(l, dif);
update0(r + 1, -dif);
}
ld query(int pos) { // sum of values in [0, pos]
pos++;
ld res = 0;
for (; pos > 0; pos &= pos - 1) res += s[pos-1];
return res;
}
};
void solve()
{
int n; cin>>n;
int c; cin>>c; c--;
vector<vector<int>> adj(n);
forn(i,0,n-1)
{
int u,v; cin>>u>>v; u--; v--;
adj[u].pb(v);
adj[v].pb(u);
}
int m; cin>>m;
vector<int> a(m);
forn(i,0,m)
{
cin>>a[i];
a[i]--;
}
int tmr=-1;
vector<int> prt(n, -1);
vector<int> in(n), out(n);
vector<bool> vst(n, false);
queue<int> q;
q.push(0);
in[0] = ++tmr;
vst[0] = 1;
while(!q.empty())
{
int u = q.front(); q.pop();
for (const int v : adj[u])
{
if (vst[v]) continue;
vst[v] = 1;
q.push(v);
prt[v] = u;
in[v] = ++tmr;
}
out[u] = tmr;
}
FT fw(n);
fw.update(in[c], in[c], 1);
ld ans = 0;
for(const int x : a)
{
ld cur = fw.query(in[x]);
ans += cur;
ld upd = cur / sz(adj[x]);
int p = prt[x];
fw.update(in[x], in[x], -cur);
fw.update(in[x] + 1, out[x], upd);
if (p != -1)
fw.update(in[p], in[p], upd);
}
cout<<setprecision(10)<<fixed;
cout<<ans<<'\n';
}
int main()
{
cin.tie(0)->sync_with_stdio(0);
int t; cin>>t;
forn(i,0,t) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 3327ms
memory: 103080kb
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:
-nan -nan
result:
wrong output format Expected double, but "-nan" found