QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#738463 | #9630. 沙堆 | huaxiamengjin | WA | 3ms | 28092kb | C++14 | 721b | 2024-11-12 19:08:00 | 2024-11-12 19:08:02 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n;
vector<int>g[1001001];
priority_queue<pair<int,int> >q;
int a[1001001];
int main(){
cin>>n;
for (int i=1,x,y;i<n;i++)
cin>>x>>y,g[x].push_back(y),g[y].push_back(x);
long long sum=0;
for (int i=1;i<=n;i++)
cin>>a[i],sum+=(int)g[i].size()-1-a[i];
if(sum<0)return cout<<-1<<"\n",0;
for (int i=1;i<=n;i++)
q.push({a[i],i});
while(q.size()){
int x=q.top().second,xx=q.top().first;
q.pop();if(xx!=a[x]||xx<g[x].size())continue;
int t=g[x].size();
for (auto y:g[x])a[y]+=a[x]/t,q.push({a[y],y});
a[x]%=t;
}
for (int i=1;i<=n;i++)
cout<<a[i]<<" ";cout<<"\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 28092kb
input:
6 1 2 2 3 2 4 1 5 4 6 1 1 0 0 1 1
output:
1 2 0 1 0 0
result:
wrong answer 1st lines differ - expected: '1 2 0 1 0 0', found: '1 2 0 1 0 0 '