QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#750653 | #9630. 沙堆 | ucup-team2179# | WA | 0ms | 3620kb | C++20 | 1.2kb | 2024-11-15 15:21:09 | 2024-11-15 15:21:10 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define db double
#define pb push_back
#define pii pair<int, int>
#define ll long long
using namespace std;
void solve() {
int n;
cin>>n;
vector<int> a[n + 1];
vector<int> c(n + 1);
vector<int> deg(n + 1);
set<pii> q;
for (int i = 1; i <= n-1; i++)
{
int u,v;
cin>>u>>v;
a[u].pb(v);
a[v].pb(u);
}
int sum = 0;
for(int i=1;i<=n;i++){
cin >> c[i];
sum += c[i];
deg[i] = a[i].size();
if(c[i]>=deg[i])
q.insert({-deg[i],i});
}
if(sum>n-2&&n!=1){
cout << -1<<'\n';
return;
}
if(n==1){
cout << c[1];
return;
}
while(!q.empty()){
auto [d,u]=*q.begin();
q.erase(q.begin());
int k=c[u]/deg[u];
c[u]=c[u]%deg[u];
for(auto p:a[u]){
c[p]+=k;
if(c[p]>=deg[p])
q.insert({-deg[p], p});
}
}
for (int i = 1;i<=n;i++)
cout << c[i] << " ";
cout << "\n";
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3620kb
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 '