QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#884260#7588. Monster HunterlopzithWA 286ms19488kbC++143.1kb2025-02-05 22:54:352025-02-05 22:54:36

Judging History

This is the latest submission verdict.

  • [2025-02-05 22:54:36]
  • Judged
  • Verdict: WA
  • Time: 286ms
  • Memory: 19488kb
  • [2025-02-05 22:54:35]
  • 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)
    {
        return std::max(x.a, x.a + y.a - x.b) > std::max(y.a, x.a + y.a - 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;
    }
    printf("%lld\n", a[1]);
}

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
}

詳細信息

Test #1:

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

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: 286ms
memory: 19488kb

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:

112474
6460765
155195854
155195854
155195854
155195854
155195854
155195854
243690710
411104041

result:

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