QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#220514#2429. Conquer The WorldlinnyxWA 40ms72216kbC++141.8kb2023-10-20 14:51:172023-10-20 14:51:17

Judging History

你现在查看的是最新测评结果

  • [2023-10-20 14:51:17]
  • 评测
  • 测评结果:WA
  • 用时:40ms
  • 内存:72216kb
  • [2023-10-20 14:51:17]
  • 提交

answer

#include "ext/pb_ds/priority_queue.hpp"
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
#define fr first
#define sc second
inline int rd() {
    int f = 1, tmp = 0;
    char ch = getchar();
    while (!isdigit(ch)) {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (isdigit(ch)) {
        tmp = tmp * 10 + (ch - '0');
        ch = getchar();
    }
    return tmp * f;
}
const int N = 2.5e5 + 10, inf = 1000000000000;
int n;
struct edge {
    int nt, to, w;
} e[N << 1];
int p[N], cnt;
inline void add(int x, int y, int z) {
    e[++cnt] = {p[x], y, z};
    p[x] = cnt;
}
int a[N], b[N], dep[N], ans;
__gnu_pbds::priority_queue<int, greater<int>> A[N], B[N];
void dfs(int x, int fa) {
    for (int i = a[x] + 1; i <= b[x]; i++)
        A[x].push(dep[x] - inf);
    for (int i = b[x] + 1; i <= a[x]; i++)
        B[x].push(dep[x]);
    for (int i = p[x]; i; i = e[i].nt) {
        int v = e[i].to, w = e[i].w;
        if (v == fa)
            continue;
        dep[v] = dep[x] + w;
        dfs(v, x);
        A[x].join(A[v]);
        B[x].join(B[v]);
    }
    while (!A[x].empty() && !B[x].empty() &&
           A[x].top() + B[x].top() - 2 * dep[x] < 0) {
        int u = A[x].top(), v = B[x].top();
        A[x].pop();
        B[x].pop();
        ans += u + v - 2 * dep[x];
        A[x].push(2 * dep[x] - v);
    }
}
signed main() {
    n = rd();
    for (int i = 1; i < n; i++) {
        int u = rd(), v = rd(), w = rd();
        add(u, v, w);
        add(v, u, w);
    }
    for (int i = 1; i <= n; i++) {
        a[i] = rd();
        b[i] = rd();
        ans += inf * max(0ll, b[i] - a[i]);
    }
    dfs(1, 0);
    cout << ans << endl;
    return 0;
}

Details

Test #1:

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

Test #2:

score: 0
Accepted
time: 2ms
memory: 22780kb

Test #3:

score: 0
Accepted
time: 2ms
memory: 21468kb

Test #4:

score: 0
Accepted
time: 0ms
memory: 21632kb

Test #5:

score: 0
Accepted
time: 0ms
memory: 22040kb

Test #6:

score: 0
Accepted
time: 0ms
memory: 21652kb

Test #7:

score: 0
Accepted
time: 0ms
memory: 21420kb

Test #8:

score: 0
Accepted
time: 0ms
memory: 22532kb

Test #9:

score: 0
Accepted
time: 16ms
memory: 48188kb

Test #10:

score: 0
Accepted
time: 29ms
memory: 47320kb

Test #11:

score: 0
Accepted
time: 40ms
memory: 72216kb

Test #12:

score: -100
Wrong Answer
time: 0ms
memory: 23200kb