QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#749982#2429. Conquer The WorldLIUIRRE 400ms129404kbC++142.7kb2024-11-15 11:50:522024-11-15 11:50:52

Judging History

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

  • [2024-11-15 11:50:52]
  • 评测
  • 测评结果:RE
  • 用时:400ms
  • 内存:129404kb
  • [2024-11-15 11:50:52]
  • 提交

answer

/*
  Author: LIUIR
  Created: 2024.11.15  11:32:44
  Last Modified: 2024.11.15  11:50:43
*/
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int N = 2.5e5 + 5;
const int M = 1e6 + 5;
const ll INF = 1e12;

int n, rtS[N], rtT[N];
ll ans, a[N], dis[N];
vector<int> edge[N];
vector<ll> val[N];

class Heap{
    private:
        int cur = 0;
        struct Node{
            int ls, rs, dist;
            ll val;
            bool operator < (const Node& rhs){return val < rhs.val;}
        }heap[M << 2];
    public:
        Heap(){heap[0].dist = -1;}
        int New(ll val)
        {
            cur++;
            heap[cur] = Node{0, 0, 0, val};
            return cur;
        }
        int Merge(int u, int v)
        {
            if (!u || !v)
                return u | v;
            if (heap[u].val > heap[v].val)
                swap(u, v);
            heap[u].rs = Merge(heap[u].rs, v);
            if (heap[heap[u].ls].dist < heap[heap[u].rs].dist)
                swap(heap[u].ls, heap[u].rs);
            heap[u].dist = heap[heap[u].rs].dist + 1;
            return u;
        }
        void Delete(int& rt){rt = Merge(heap[rt].ls, heap[rt].rs);}
        friend void Work(int);
}heap;

void Work(int);
void Dfs(int, int);

signed main()
{
    scanf("%d", &n);
    for (int i = 1, u, v, w; i < n; i++)
    {
        scanf("%d%d%d", &u, &v, &w);
        edge[u].push_back(v);
        edge[v].push_back(u);
        val[u].push_back(w);
        val[v].push_back(w);
    }
    for (int i = 1, x, y; i <= n; i++)
        scanf("%d%d", &x, &y), a[i] = x - y;
    Dfs(1, 0);
    for (int i = 1; i <= n; i++)if (a[i] < 0)
        ans += -a[i] * INF;
    printf("%lld\n", ans);
    return 0;
}

void Work(int u)
{
    while(rtS[u] && rtT[u] && heap.heap[rtS[u]].val + heap.heap[rtT[u]].val - 2ll * dis[u] < 0)
    {
        ll s = heap.heap[rtS[u]].val, t = heap.heap[rtT[u]].val;
        ans += s + t - 2ll * dis[u];
        heap.Delete(rtS[u]), heap.Delete(rtT[u]);
        rtS[u] = heap.Merge(rtS[u], heap.New(2ll * dis[u] - t));
        rtT[u] = heap.Merge(rtT[u], heap.New(2ll * dis[u] - s));
    }
}
void Dfs(int u, int fa)
{
    if (a[u] > 0)
    {
        for (int i = 1; i <= a[u]; i++)
            rtS[u] = heap.Merge(rtS[u], heap.New(dis[u]));
    }
    else
    {
        for (int i = 1; i <= -a[u]; i++)
            rtT[u] = heap.Merge(rtT[u], heap.New(dis[u] - INF));
    }
    for (int i = 0; i < edge[u].size(); i++)
    {
        int v = edge[u][i];
        if (v == fa)
            continue;
        dis[v] = dis[u] + val[u][i];
        Dfs(v, u);
        rtS[u] = heap.Merge(rtS[u], rtS[v]);
        rtT[u] = heap.Merge(rtT[u], rtT[v]);
    }
    Work(u);
}

详细

Test #1:

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

Test #2:

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

Test #3:

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

Test #4:

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

Test #5:

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

Test #6:

score: 0
Accepted
time: 5ms
memory: 22516kb

Test #7:

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

Test #8:

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

Test #9:

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

Test #10:

score: 0
Accepted
time: 56ms
memory: 49300kb

Test #11:

score: 0
Accepted
time: 65ms
memory: 51552kb

Test #12:

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

Test #13:

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

Test #14:

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

Test #15:

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

Test #16:

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

Test #17:

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

Test #18:

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

Test #19:

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

Test #20:

score: 0
Accepted
time: 83ms
memory: 74048kb

Test #21:

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

Test #22:

score: 0
Accepted
time: 110ms
memory: 37320kb

Test #23:

score: 0
Accepted
time: 129ms
memory: 40276kb

Test #24:

score: 0
Accepted
time: 67ms
memory: 32856kb

Test #25:

score: 0
Accepted
time: 79ms
memory: 34008kb

Test #26:

score: 0
Accepted
time: 141ms
memory: 39820kb

Test #27:

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

Test #28:

score: 0
Accepted
time: 120ms
memory: 54172kb

Test #29:

score: 0
Accepted
time: 168ms
memory: 67132kb

Test #30:

score: 0
Accepted
time: 246ms
memory: 119504kb

Test #31:

score: 0
Accepted
time: 233ms
memory: 87168kb

Test #32:

score: 0
Accepted
time: 183ms
memory: 73592kb

Test #33:

score: 0
Accepted
time: 206ms
memory: 69472kb

Test #34:

score: 0
Accepted
time: 400ms
memory: 100340kb

Test #35:

score: 0
Accepted
time: 221ms
memory: 67616kb

Test #36:

score: 0
Accepted
time: 241ms
memory: 75780kb

Test #37:

score: 0
Accepted
time: 310ms
memory: 129404kb

Test #38:

score: -100
Runtime Error