QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#235575#7588. Monster HunterJooDdaeWA 550ms23660kbC++201.4kb2023-11-02 22:08:002023-11-02 22:08:01

Judging History

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

  • [2023-11-02 22:08:01]
  • 评测
  • 测评结果:WA
  • 用时:550ms
  • 内存:23660kb
  • [2023-11-02 22:08:00]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const ll INF = 1e18;

int n, par[200200], p[200200];
ll a[200200], b[200200], c[200200], d[200200];
vector<int> v[200200];
priority_queue<array<ll, 4>> pq;

void dfs(int u, int p) {
    par[u] = p;
    for(auto x : v[u]) if(x != p) dfs(x, u);
}

int find(int x) {
    if(x == p[x]) return x;
    return p[x] = find(p[x]);
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    int tc; cin >> tc;
    while(tc--) {
        cin >> n;
        for(int i=1;i<=n;i++) v[i].clear();
        while(!pq.empty()) pq.pop();

        for(int i=2;i<=n;i++) cin >> a[i] >> b[i];
        for(int i=1;i<n;i++) {
            int x, y; cin >> x >> y;
            v[x].push_back(y), v[y].push_back(x);
        }

        dfs(1, 0);
        iota(p+1, p+1+n, 1);

        for(int i=2;i<=n;i++) c[i] = b[i]-a[i], d[i] = -a[i];
        for(int i=2;i<=n;i++) pq.push({c[i]>0, d[i], c[i], i});

        while(!pq.empty()) {
            auto [t, D, C, u] = pq.top(); pq.pop();
            if(D != d[u] || C != c[u]) continue;

            int x = find(par[u]);
            p[u] = x;

            if(D || C) {
                d[x] = min(d[x], c[x]+D), c[x] += C;
                if(x != 1) pq.push({c[x]>0, d[x], c[x], x});
            }
        }

        cout << -d[1] << "\n";
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 15552kb

input:

1
4
2 6
5 4
6 2
1 2
2 3
3 4

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: -100
Wrong Answer
time: 550ms
memory: 23660kb

input:

10
50000
112474 198604
847262 632597
871374 962220
971398 284540
10360 695245
43233 569941
64019 203468
598469 997911
41841 657552
333198 936119
546370 180011
58831 901040
959767 396595
710441 277461
429299 209831
494164 138327
393982 581911
993164 617488
108113 160310
55841 611360
301395 291074
149...

output:

63548062
613528616
796269298
796269298
796269298
796269298
796269298
796269298
796269298
796269298

result:

wrong answer 1st numbers differ - expected: '63495498', found: '63548062'