QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#788807#7588. Monster HunterHunsterWA 1ms7868kbC++231.6kb2024-11-27 18:22:242024-11-27 18:22:26

Judging History

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

  • [2024-11-27 18:22:26]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7868kb
  • [2024-11-27 18:22:24]
  • 提交

answer

#include <bits/stdc++.h>

using LL = long long;

constexpr int N = 100005;

struct Val { 
    LL x, y; 
    friend bool operator<(Val a, Val b) {
        if (a.y >= 0 && b.y < 0) return 1;
        if (a.y < 0 && b.y >= 0) return 0;
        if (a.y < 0) return std::max(a.x, b.x - a.y) < std::max(b.x, a.x - b.y);
        else return a.x < b.x;
    }
};

int n;
Val val[N];
int fa[N], par[N], g[N];
std::vector<int> tree[N];

void predfs(int u, int p) {
    fa[u] = p;
    for (int v : tree[u]) {
        if (v == p) continue;
        predfs(v, u);
    }
}
int find_par(int x) { return par[x] == x ? x : par[x] = find_par(par[x]); }

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cin >> n;
    for (int i = 2; i <= n; i++) {
        int a, b;
        std::cin >> a >> b;
        val[i] = {a, b - a};
    }
    for (int i = 1; i < n; i++) {
        int x, y;
        std::cin >> x >> y;
        tree[x].push_back(y);
        tree[y].push_back(x);
    }
    predfs(1, 0);
    std::priority_queue<std::tuple<Val, int, int>, std::vector<std::tuple<Val, int, int>>, std::greater<std::tuple<Val, int, int>>> que;
    for (int i = 2; i <= n; i++) que.push({val[i], i, g[i]});
    std::iota(par + 1, par + n + 1, 1);
    while (que.size()) {
        auto [v, x, t] = que.top();
        que.pop();
        if (x == 1) continue;
        if (t != g[x]) continue;
        int p = find_par(fa[x]);
        val[p].x = std::max(val[p].x, v.x - val[p].y);
        val[p].y += v.y;
        que.push({val[p], p, ++g[p]});
        par[x] = p;
    }
    printf("%lld\n", val[1].x);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 7868kb

input:

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

output:

0

result:

wrong answer 1st numbers differ - expected: '3', found: '0'