QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#64642 | #4433. Kitten and Roomba | As3b_team_f_masr | RE | 0ms | 0kb | C++ | 3.8kb | 2022-11-25 05:12:34 | 2022-11-25 05:12:35 |
Judging History
answer
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define sc second
#define EPS 1e-9
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define EPS 1e-9
#define PI acos(-1.0)
#define ll long long
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
#define pb push_back
#define ft first
#define sc second
#define pi pair<ll,ll>
#define vi vector<ll>
#define sz(s) s.size()
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll N = 1e6+5, M = 300 + 5, MOD = 1e4+5, INF = 1e18;
int dx[] = {-1, 1, 0, 0}, Dx[] = {-1, -1, 0, 1, 1, 1, 0, -1};;
int dy[] = {0, 0, 1, -1}, Dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
int n, m, tt, ID[N], timer, mx[N],p[N];
vi g[N];
double seg[N*4], lazy[N*4];
void bfs(int s)
{
queue<int> q;
q.push(s);
ID[s] = ++timer;
while(sz(q))
{
int node = q.front(); q.pop();
for(auto it:g[node])
{
if(!ID[it]){
ID[it] = ++timer;
q.push(it);
p[it]=s;
}
}
}
}
void dfs(int s,int p)
{
int tmp = ID[s];
for(auto it:g[s])
{
tmp = max(tmp,ID[it]);
}
mx[s] = tmp;
for(auto it:g[s])
{
if(it != p)
{
dfs(it,s);
}
}
}
void check(int v,int l,int r)
{
if(lazy[v]-EPS > 0)
{
seg[v] = lazy[v];
if(l != r){
lazy[v*2] += lazy[v];
lazy[v*2+1] += lazy[v];
}
lazy[v] = 0;
}
}
void update(int v,int l,int r,int s,int e, double val)
{
check(v,l,r);
if(l >= s && r <= e)
{
lazy[v] += val;
check(v,l,r);
return;
}
if(l > e || r < s) return;
int mid = (l+r) / 2;
update(v*2,l,mid,s,e,val);
update(v*2+1,mid+1,r,s,e,val);
seg[v] = seg[v*2] + seg[v*2+1];
}
double get(int v,int l,int r,int s,int e)
{
check(v,l,r);
if(l > e || r < s) return 0;
if(l >= s && r <= e) return seg[v];
int mid = (l+r) / 2;
return get(v*2,l,mid,s,e) + get(v*2+1,mid+1,r,s,e);
}
int main()
{
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t;
cin>>t;
while(t--)
{
int c;
cin >> n;
cin >> c;
for(int i=0;i<=n*2;i++)
{
ID[i]=mx[i]=p[i]=seg[i]=lazy[i]=0;
}
for(int i=0;i<=n+1;i++)g[i].clear();
timer=0;
for(int i = 1; i < n;++i)
{
int u , v;
cin >> u >> v;
g[u].pb(v);
g[v].pb(u);
}
bfs(1);
dfs(1,1);
update(1,1,n,ID[c],ID[c],1);
int m;
cin>>m;
double ans=0;
cout<<fixed<<setprecision(6);
for(int i=0;i<m;i++)
{
int room;
cin>>room;
double cur=get(1,1,n,ID[room],ID[room]);
ans+=cur;
///update childs
update(1,1,n,mx[room]-g[room].size()+1,mx[room],cur/(double)g[room].size());
update(1,1,n,ID[p[room]],ID[p[room]],cur/(double)g[room].size());
///update room
update(1,1,n,ID[room],ID[room],-cur);
}
cout<<ans<<'\n';
}
return 0;
}
/*
2
3 3 1
.XX
XXX
XX.
3 4 1
..XX
X.XX
X..X
3 1
1 2
2 3
4
1 2 3 2
1.0000000000
1.0000000000
0.5000000000
0.5000000000
3.0000000000*/
详细
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...