QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#884030#7588. Monster HunterWTR2007WA 365ms21352kbC++202.2kb2025-02-05 21:00:132025-02-05 21:00:14

Judging History

This is the latest submission verdict.

  • [2025-02-05 21:00:14]
  • Judged
  • Verdict: WA
  • Time: 365ms
  • Memory: 21352kb
  • [2025-02-05 21:00:13]
  • 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;
    q.push((node){0, 0, 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;
        if (id == 1) continue;
        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.Merge(top, id);
    }
    printf("%lld\n", x[1]);
    for (int i = 1; i <= n; i++) e[i].clear(), vis[i] = 0;
}
signed main() {
    int _ = 1;
#if MULT_TEST
    _ = read();
#endif 
    while (_--) Solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 365ms
memory: 21352kb

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:

7770705619449021
148870061292728363
9222764024655196876
9222764024655196876
9222764024655196876
9222764024655196876
9222764024655196876
9222764024655196876
9222764024655196876
9222764024655196876

result:

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