QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#220517#2429. Conquer The WorldlinnyxAC ✓443ms148884kbC++141.8kb2023-10-20 14:52:072023-10-20 14:52:07

Judging History

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

  • [2023-10-20 14:52:07]
  • 评测
  • 测评结果:AC
  • 用时:443ms
  • 内存:148884kb
  • [2023-10-20 14:52:07]
  • 提交

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);
        B[x].push(2 * dep[x] - u);
    }
}
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;
}

详细

Test #1:

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

Test #2:

score: 0
Accepted
time: 4ms
memory: 22320kb

Test #3:

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

Test #4:

score: 0
Accepted
time: 4ms
memory: 21948kb

Test #5:

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

Test #6:

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

Test #7:

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

Test #8:

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

Test #9:

score: 0
Accepted
time: 12ms
memory: 49324kb

Test #10:

score: 0
Accepted
time: 35ms
memory: 52624kb

Test #11:

score: 0
Accepted
time: 50ms
memory: 75136kb

Test #12:

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

Test #13:

score: 0
Accepted
time: 4ms
memory: 22656kb

Test #14:

score: 0
Accepted
time: 4ms
memory: 22564kb

Test #15:

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

Test #16:

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

Test #17:

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

Test #18:

score: 0
Accepted
time: 8ms
memory: 24656kb

Test #19:

score: 0
Accepted
time: 10ms
memory: 34880kb

Test #20:

score: 0
Accepted
time: 72ms
memory: 86372kb

Test #21:

score: 0
Accepted
time: 28ms
memory: 33300kb

Test #22:

score: 0
Accepted
time: 28ms
memory: 33096kb

Test #23:

score: 0
Accepted
time: 32ms
memory: 34888kb

Test #24:

score: 0
Accepted
time: 19ms
memory: 29584kb

Test #25:

score: 0
Accepted
time: 21ms
memory: 32392kb

Test #26:

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

Test #27:

score: 0
Accepted
time: 60ms
memory: 67420kb

Test #28:

score: 0
Accepted
time: 71ms
memory: 53804kb

Test #29:

score: 0
Accepted
time: 89ms
memory: 83700kb

Test #30:

score: 0
Accepted
time: 174ms
memory: 115724kb

Test #31:

score: 0
Accepted
time: 140ms
memory: 95324kb

Test #32:

score: 0
Accepted
time: 95ms
memory: 86960kb

Test #33:

score: 0
Accepted
time: 94ms
memory: 84776kb

Test #34:

score: 0
Accepted
time: 200ms
memory: 101080kb

Test #35:

score: 0
Accepted
time: 78ms
memory: 88232kb

Test #36:

score: 0
Accepted
time: 127ms
memory: 93356kb

Test #37:

score: 0
Accepted
time: 244ms
memory: 121492kb

Test #38:

score: 0
Accepted
time: 313ms
memory: 148068kb

Test #39:

score: 0
Accepted
time: 190ms
memory: 141440kb

Test #40:

score: 0
Accepted
time: 211ms
memory: 98844kb

Test #41:

score: 0
Accepted
time: 157ms
memory: 109200kb

Test #42:

score: 0
Accepted
time: 126ms
memory: 97432kb

Test #43:

score: 0
Accepted
time: 109ms
memory: 97364kb

Test #44:

score: 0
Accepted
time: 122ms
memory: 101036kb

Test #45:

score: 0
Accepted
time: 155ms
memory: 111464kb

Test #46:

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

Test #47:

score: 0
Accepted
time: 28ms
memory: 66920kb

Test #48:

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

Test #49:

score: 0
Accepted
time: 88ms
memory: 81696kb

Test #50:

score: 0
Accepted
time: 27ms
memory: 34752kb

Test #51:

score: 0
Accepted
time: 4ms
memory: 23096kb

Test #52:

score: 0
Accepted
time: 3ms
memory: 22312kb

Test #53:

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

Test #54:

score: 0
Accepted
time: 3ms
memory: 21756kb

Test #55:

score: 0
Accepted
time: 3ms
memory: 22824kb

Test #56:

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

Test #57:

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

Test #58:

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

Test #59:

score: 0
Accepted
time: 33ms
memory: 39348kb

Test #60:

score: 0
Accepted
time: 58ms
memory: 56200kb

Test #61:

score: 0
Accepted
time: 226ms
memory: 117604kb

Test #62:

score: 0
Accepted
time: 260ms
memory: 123148kb

Test #63:

score: 0
Accepted
time: 161ms
memory: 139048kb

Test #64:

score: 0
Accepted
time: 153ms
memory: 139104kb

Test #65:

score: 0
Accepted
time: 443ms
memory: 139032kb

Test #66:

score: 0
Accepted
time: 429ms
memory: 138968kb

Test #67:

score: 0
Accepted
time: 172ms
memory: 129656kb

Test #68:

score: 0
Accepted
time: 181ms
memory: 147512kb

Test #69:

score: 0
Accepted
time: 185ms
memory: 148884kb

Test #70:

score: 0
Accepted
time: 171ms
memory: 148264kb