QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#789454#7588. Monster Hunterkonata2828WA 1ms7128kbC++141.9kb2024-11-27 20:24:552024-11-27 20:24:56

Judging History

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

  • [2024-11-27 20:24:56]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7128kb
  • [2024-11-27 20:24:55]
  • 提交

answer

// Hydro submission #67470f959592d6097b86f66f@1732710293940
#include <bits/stdc++.h>
using namespace std;
int read() {
    int x = 0, f = 1; char c = getchar();
    while (c < '0' || c > '9') {if (c == '-') f = -f; c = getchar();}
    while (c >= '0' && c <= '9') {x = x * 10 + (c ^ 48); c = getchar();}
    return x * f;
}
typedef pair <int, int> pii;
typedef long long LL;
const int N = 1e5 + 5;
int n;
LL ans;
vector <int> e[N];
LL a[N], b[N];
int fa[N], f[N], vis[N];
struct Node {
    LL a, b;
    int x;
    bool operator < (const Node &B) const {
        int op1 = (a <= b), op2 = (B.a <= B.b);
        if (op1 ^ op2) return op1 < op2;
        if (op1) return a > B.a;
        return b < B.b;
    }
} ;
priority_queue <Node> Q;
void dfs(int x, int dad) {
    fa[x] = dad;
    for (int y : e[x]) {
        if (y == dad) continue;
        dfs(y, x);
    }
}
int find(int x) {
    return x == f[x] ? x : f[x] = find(f[x]);
}
void Solve() {
    n = read();
    for (int i = 2; i <= n; i++) {
        a[i] = read();
        b[i] = read();
    }
    for (int i = 1; i < n; i++) {
        int u = read(), v = read();
        e[u].push_back(v);
        e[v].push_back(u);
    }
    dfs(1, 0);
    for (int i = 1; i <= n; i++) f[i] = i;
    for (int i = 2; i <= n; i++) Q.push((Node){a[i], b[i], i});
    LL s = 0;
    while (Q.size()) {
        Node p = Q.top(); Q.pop(); int x = p.x;
        if (vis[x]) continue;
        int y = find(fa[x]); vis[x] = 1;
        if (y == 1 || vis[y]) {
            s += a[x]; ans = max(ans, s);
            s -= b[x]; continue;
        }
        LL c = max(a[y], a[y] + a[x] - b[y]);
        b[y] = b[y] + b[x] - a[x] - a[y] + c; a[y] = c;
        Q.push((Node){a[y], b[y], y}); f[x] = y;
    }
    printf("%lld\n", ans);
}
int main() {
    // freopen(".in", "r", stdin);
    // freopen(".out", "w", stdout);
    int _ = 1;
    while (_--) Solve();
    return 0;
}

详细

Test #1:

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

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'