QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#738413 | #9532. 长野原龙势流星群 | urosk | 0 | 0ms | 0kb | C++17 | 2.3kb | 2024-11-12 19:00:22 | 2024-11-12 19:00:23 |
answer
#define here cerr<<"===========================================\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#include <bits/stdc++.h>
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define eb emplace_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define cer(a) {cerr<<#a<<": ";for(ll x_ : a) cerr<<x_<< " ";cerr<<endl;}
#define si(a) (ll)(a.size())
using namespace std;
using ld = double;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pld = pair<ld,ld>;
#define mod 1
ll add(ll x,ll y){
x+=y;
if(x<0){
x%=mod;
x+=mod;
}else{
if(x>=mod) x%=mod;
}
return x;
}
ll mul(ll a,ll b){
a = add(a,0);
b = add(b,0);
ll ans = (a*b)%mod;
if(ans<0) ans+=mod;
return ans;
}
const ll maxn = 200005;
ll n;
ll a[maxn];
ll par[maxn];
ll dsu[maxn];
ll sz[maxn];
ll root(ll x) {
while(dsu[x]!=x) {
dsu[x] = dsu[dsu[x]];
x = dsu[x];
}
return x;
}
ll dub[maxn];
bool cmp(ll i,ll j) {
i = root(i),j = root(j);
pll c = {a[i],sz[i]};
pll b = {a[j],sz[j]};
if(c.fi*b.sc==c.sc*b.fi) return dub[i]<dub[j];
return c.fi*b.sc<c.sc*b.fi;
}
ld ans[maxn];
/**
6
1 2 2 1 4
3 1 5 6 6 7
*/
vector<ll> g[maxn];
void dfs(ll u) {
for(ll s : g[u]) {
dub[s] = dub[u] + 1;
dfs(s);
}
}
void tc(){
cin >> n;
cout<<fixed<<setprecision(10);
for(ll i = 2;i<=n;i++) cin >> par[i];
for(ll i = 2;i<=n;i++) g[par[i]].pb(i);
dfs(1);
for(ll i = 1;i<=n;i++) cin >> a[i];
set<ll,decltype(&cmp)> pq(cmp);
for(ll i = 1;i<=n;i++) {
dsu[i] = i;
sz[i] = 1;
pq.insert(i);
}
while(si(pq)) {
ll i = *prev(pq.end());
pq.erase(prev(pq.end()));
ans[i] = a[i]*1.0/sz[i];
//dbg(i);
if(i==1) continue;
ll j = par[i];
i = root(i),j = root(j);
pq.erase(pq.find(j));
dsu[i] = j;
sz[j]+=sz[i];
a[j]+=a[i];
pq.insert(j);
}
for(ll i = 1;i<=n;i++) cout<<ans[i]<<endl;
}
int main(){
ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
int t; t = 1;
while(t--){
tc();
}
return (0-0);
}
详细
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
input:
2000 1 2 2 4 5 2 3 6 4 2 7 2 8 14 8 12 1 14 4 14 8 18 9 2 7 22 20 22 14 29 28 16 6 21 23 6 21 14 13 9 1 4 18 13 2 39 21 33 18 20 38 27 27 1 49 5 51 3 31 24 10 42 2 44 13 9 35 66 27 60 67 59 29 40 53 2 33 43 26 43 62 16 78 45 14 10 73 69 41 35 25 26 2 70 54 1 54 48 5 36 44 28 90 29 51 51 93 82 95 45 ...
output:
result:
Subtask #2:
score: 0
Runtime Error
Test #32:
score: 0
Runtime Error
input:
200000 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 52 52...
output:
result:
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #2:
0%