QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#750623#9630. 沙堆ucup-team2179#WA 0ms3568kbC++201.2kb2024-11-15 15:13:472024-11-15 15:13:48

Judging History

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

  • [2024-11-15 15:13:48]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3568kb
  • [2024-11-15 15:13:47]
  • 提交

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){
        cout << -1<<'\n';
        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] << " ";
}
signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3568kb

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 '