QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#884092#7588. Monster HunterWTR2007WA 369ms21204kbC++202.2kb2025-02-05 21:17:052025-02-05 21:17:05

Judging History

This is the latest submission verdict.

  • [2025-02-05 21:17:05]
  • Judged
  • Verdict: WA
  • Time: 369ms
  • Memory: 21204kb
  • [2025-02-05 21:17:05]
  • Submitted

answer

#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define MULT_TEST 1
using namespace std;
typedef long double ldb;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const int MOD = 998244353;
const int N = 100005;
int f[N], x[N], y[N];
bool vis[N];
vector<int> e[N];
struct node {
    int a, b, id;
    bool operator < (const node &T) const {
        return max(a, a + T.a - b) < max(T.a, a + T.a - T.b);
    }
};
struct dsu {
    vector<int> fa;
    dsu(int n) : fa(n + 2) { iota(fa.begin(), fa.end(), 0); };
    inline int Find(int r) {
        while (r != fa[r]) r = fa[r] = fa[fa[r]];
        return r;
    }
    inline bool Merge(int x, int y) {
        x = Find(x); y = Find(y);
        if (x == y) return true;
        else return fa[y] = x, false;
    }
};
inline int read() {
    int w = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        w = (w << 1) + (w << 3) + ch - 48;
        ch = getchar();
    }
    return w * f;
}
inline void DFS(int x) {
    for (auto u : e[x]) {
        if (u == f[x]) continue;
        f[u] = x, DFS(u);
    }
}
inline void Solve() {
    int n;
    n = read();
    priority_queue<node> q;
    vis[1] = 1;
    for (int i = 2; i <= n; i++) {
        x[i] = read(), y[i] = read();
        q.push((node){x[i], y[i], i});
    }
    for (int i = 1; i < n; i++) {
        int u = read(), v = read();
        e[u].push_back(v), e[v].push_back(u);
    }
    DFS(1);
    dsu A(n);
    while (!q.empty()) {
        auto [a, b, id] = q.top(); q.pop();
        if (vis[id]) continue;
        vis[id] = 1;
        int top = A.Find(f[id]);
        x[top] = max(x[top], x[top] - y[top] + x[id]);
        y[top] = y[top] - x[id] + y[id];
        q.push((node){x[top], y[top], top});
        A.fa[id] = top;
    }
    printf("%lld\n", x[1]);
    for (int i = 1; i <= n; i++) 
        e[i].clear(), f[i] = x[i] = y[i] = vis[i] = 0;
}
signed main() {
    int _ = 1;
#if MULT_TEST
    _ = read();
#endif 
    while (_--) Solve();
    return 0;
}

詳細信息

Test #1:

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

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: 369ms
memory: 21204kb

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:

7770705614895362
135480654518231002
9220920515812781749
903066370691362916
1180257939858935731
6169084423162673000
9223230513937026327
9221475355469086050
886678648085979192
938700058835436587

result:

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