QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#738463#9630. 沙堆huaxiamengjinWA 3ms28092kbC++14721b2024-11-12 19:08:002024-11-12 19:08:02

Judging History

你现在查看的是最新测评结果

  • [2024-11-12 19:08:02]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:28092kb
  • [2024-11-12 19:08:00]
  • 提交

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 '