QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#884017 | #7588. Monster Hunter | WTR2007 | WA | 401ms | 21288kb | C++20 | 2.2kb | 2025-02-05 20:53:17 | 2025-02-05 20:53:17 |
Judging History
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] = max(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: 5836kb
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: 401ms
memory: 21288kb
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:
3040731 3040731 3040731 3040731 3040731 3040731 3040731 3040731 3040731 3040731
result:
wrong answer 1st numbers differ - expected: '63495498', found: '3040731'