QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#884351#7588. Monster HunterlopzithWA 818ms19580kbC++143.3kb2025-02-06 00:25:422025-02-06 00:25:50

Judging History

This is the latest submission verdict.

  • [2025-02-06 00:25:50]
  • Judged
  • Verdict: WA
  • Time: 818ms
  • Memory: 19580kb
  • [2025-02-06 00:25:42]
  • Submitted

answer

#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
#define DEFAULT 5e5 + 5
#define int long long
#define i64 long long
#define i128 __int128
#define ull unsigned long long
#define db double
#define ldb long double
#define Arr std::vector
#define Ptn std::pair
#define fi first
#define se second
#define eb emplace_back
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define popc(x) __builtin_popcountll(x)
#define clz(x) __builtin_clzll(x)
#define ctz(x) __builtin_ctzll(x)
#define chkmin(x, y) x = std::min(x, y)
#define chkmax(x, y) x = std::max(x, y)
#define FILE(x) freopen(x ".in", "r", stdin), freopen(x ".out", "w", stdout)
#define TEST(x) freopen(x ".in", "r", stdin), freopen("test.out", "w", stdout)
#define KEL(x) freopen(x ".in", "r", stdin), freopen("a.out", "w", stdout)
#define debug std::cout << "Running on " << __FUNCTION__ << ' ' << __LINE__ << std::endl;
#define fail assert(0);
#define lopzith return 0;
bool BeginPoint;
const int INF = 0x3f3f3f3f, llINF = 0x3f3f3f3f3f3f3f3f, P = 998244353;
const db eps = 1e-9;
const ull base = 13331;
const int N = 1e5 + 5;
int _, n, a[N], b[N], fa[N], _fa[N], vis[N];
Arr<int> e[N];
struct LOP
{
    int a, b, id;
    friend bool operator < (LOP x, LOP y)
    {
        bool flx = (x.a <= x.b), fly = (y.a <= y.b);
        if (flx != fly) return (x.b - x.a > y.b - y.a);
        if (flx) return x.a > y.a;
        else return x.b < y.b;
    }
};
std::priority_queue<LOP> S;
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 << 3) + (w << 1) + (ch - 48);
        ch = getchar();
    }
    return w * f;
}

void DFS(int p)
{
    for (auto to : e[p])
    {
        if (to == fa[p]) continue;
        fa[to] = p;
        DFS(to);
    }
}

int find(int x) { return _fa[x] == x ? x : _fa[x] = find(_fa[x]); }

void Solve()
{
    vis[1] = 1;
    while (!S.empty())
    {
        auto x = S.top(); S.pop();
        if (vis[x.id] || x.a != a[x.id] || x.b != b[x.id]) continue;
        vis[x.id] = 1;
        int Fa = find(fa[x.id]);
        int A = std::max(a[Fa], a[Fa] - b[Fa] + a[x.id]), B = A + b[Fa] + b[x.id] - a[Fa] - a[x.id];
        a[Fa] = A, b[Fa] = B;
        _fa[x.id] = Fa;
        S.push((LOP){a[Fa], b[Fa], Fa});
    }
    printf("%lld\n", a[1]);
    for (int i = 1; i <= n; i++) a[i] = b[i] = 0;
}

bool EndPoint;
signed main()
{
    std::cerr << "Memory = " << fabs(&BeginPoint - &EndPoint) / 1048576.0 << "MB" << std::endl;

    _ = read();
    while (_--)
    {
        n = read(); 
        while (!S.empty()) S.pop();
        for (int i = 2; i <= n; i++)
        {
            int A = read(), B = read();
            a[i] = A, b[i] = B;
            S.push((LOP){A, B, i});
        }
        for (int i = 0; i <= n; i++)
        {
            _fa[i] = i, fa[i] = vis[i] = 0;
            e[i].clear();
        } // clear
        for (int i = 1; i < n; i++)
        {
            int u = read(), v = read();
            e[u].eb(v), e[v].eb(u);
        }
        DFS(1);
        Solve();
    }

    std::cerr << "Time = " << (double)clock() / CLOCKS_PER_SEC << "s" << std::endl;
    lopzith
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 9992kb

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: 818ms
memory: 19580kb

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:

4422133501
31824432055
1787813892847
11826842889802
11722806225292
11529744386430
9466166069832
4823186517618
11657579926048
11797006654885

result:

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