QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#235262 | #6430. Monster Hunter | Yangmf# | WA | 0ms | 34320kb | C++17 | 2.5kb | 2023-11-02 16:32:43 | 2023-11-02 16:32:43 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
#define ld long double
#define M(x) \
{ \
x %= mod; \
if (x < 0) \
x += mod; \
}
#define error \
{ \
cout << "No\n"; \
return; \
}
#define all(x) (x.begin(), x.end())
template <typename A, typename B>
bool smax(A &a, const B &b) { return a < b ? a = b, 1 : 0; }
template <typename A, typename B>
bool smin(A &a, const B &b) { return b < a ? a = b, 1 : 0; }
const int N = 1e6 + 10;
int a[N];
int n, m, k;
const int inf = 1e18;
ld eps = 1e-9;
bool eql(ld x, ld y) { return fabs(x - y) < eps; }
bool lt(ld x, ld y) { return !eql(x, y) && x < y; }
bool rt(ld x, ld y) { return !eql(x, y) && x > y; }
vector<int> ed[N];
int fa[N];
int ans[N];
set<pii> q;
vector<int> res;
bool vis[N];
void solve()
{
int n;
cin>>n;
for(int i=2;i<=n;i++){
cin>>fa[i];
ed[fa[i]].push_back(i);
}
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++){
ans[i]+=a[i];
ans[fa[i]]+=a[i];
if(i!=1) ans[i]+=a[i];
}
int now=0;
for(int i=1;i<=n;i++){
now+=ans[i];
if(i!=1) now-=a[i];
// cout<<ans[i]<<" ";
q.insert({ans[i],i});
}
res.push_back(now);
// cout<<q.size()<<"\n";
vis[0]=1;
for(int i=1;i<=n;i++){
// cout<<q.size()<<"\n";
auto pr=--q.end();
int val=pr->first,x=pr->second;
q.erase(pr);
// cout << "World\n";
now-=val;
res.push_back(now);
// cout<<ans[fa[x]]<<" "<<fa[x]<<"\n";
if(vis[fa[x]]==0){
q.erase(q.lower_bound({ans[fa[x]], fa[x]}));
ans[fa[x]] -= a[x];
q.insert({ans[fa[x]], fa[x]});
}
vis[x]=1;
for(int y:ed[x]){
if(vis[y]) continue;
q.erase(q.lower_bound({ans[y],y}));
ans[y]-=a[y];
q.insert({ans[y],y});
}
}
for(int i=0;i<res.size();i++){
cout<<res[i]<<" \n"[i==n];
}
res.clear();
q.clear();
for(int i=0;i<=n+2;i++){
ans[i]=a[i]=fa[i]=0;
ed[i].clear();
vis[i]=0;
}
}
signed main()
{
// ios::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
int t;
cin >> t;
while (t--)
{
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 34320kb
input:
3 5 1 2 3 4 1 2 3 4 5 9 1 2 3 4 3 4 6 6 8 4 9 4 4 5 2 4 1 12 1 2 2 4 5 3 4 3 8 10 11 9 1 3 5 10 10 7 3 7 9 4 9
output:
29 16 9 4 1 0 74 47 35 25 15 11 7 3 1 0 145 115 93 73 55 42 32 22 15 8 4 1 0
result:
wrong answer 25th words differ - expected: '14', found: '15'