QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#467825#2429. Conquer The WorldxuqinRE 350ms103696kbC++142.4kb2024-07-08 17:38:192024-07-08 17:38:20

Judging History

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

  • [2024-07-08 17:38:20]
  • 评测
  • 测评结果:RE
  • 用时:350ms
  • 内存:103696kb
  • [2024-07-08 17:38:19]
  • 提交

answer

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cassert>
#include<cmath>
#include<utility>
#define eb emplace_back

using namespace std;
const int maxn=2.5e5+10, inf=1e9+10;
const double eps=1e-10;
typedef long long LL;
typedef pair<int, int> pii;

inline int read() {
    int x=0, f=1; char c=getchar();
    for(; c<'0'||c>'9'; c=getchar()) if(c=='-') f=0;
    for(; c>='0'&&c<='9'; c=getchar()) x=x*10+c-'0';
    return f?x:-x;
}
struct pj{
    int y, nxt, d;
} g[maxn<<1];
int len, la[maxn];
inline void add_e(int x, int y, int d) {g[++len].y=y; g[len].nxt=la[x]; la[x]=len; g[len].d=d;}
int a[maxn]; LL dis[maxn];

void dfs(int x, int F) {
    for(int i=la[x]; i; i=g[i].nxt) {
        int y=g[i].y;
        if(y!=F) dis[y]=dis[x]+g[i].d, dfs(y, x);
    }
}
const LL M=5e12;
struct tg{
    int lc, rc, d; LL val;
} tr[5000020]; int cnt;

inline int add_n(LL val) {
    int u=++cnt;
    tr[u].val=val; tr[u].d=1;
    tr[u].lc=tr[u].rc=0;
    return u;
}
int merge(int x, int y) {
    if(x==0||y==0) return x^y;
    if(tr[x].val>tr[y].val) swap(x, y);
    tr[x].rc=merge(tr[x].rc, y);
    if(tr[tr[x].rc].d>tr[tr[x].lc].d) swap(tr[x].lc, tr[x].rc);
    tr[x].d=tr[tr[x].rc].d+1;
    return x;
}
//small
int up[maxn], dn[maxn];

LL ans;
void sol(int x, int F) {
   // printf("x=%d dis[x]=%lld\n", x, dis[x]);
    for(int i=la[x]; i; i=g[i].nxt) {
        int y=g[i].y;
        if(y!=F) sol(y, x), up[x]=merge(up[x], up[y]), dn[x]=merge(dn[x], dn[y]);
    }
    if(a[x]>0) {
        for(int i=1; i<=a[x]; ++i) up[x]=merge(up[x], add_n(dis[x]));
    } else if(a[x]<0) {
        for(int i=1; i<=-a[x]; ++i) dn[x]=merge(dn[x], add_n(dis[x]-M));
    }
    while(up[x]&&dn[x]&&tr[up[x]].val+tr[dn[x]].val-2*dis[x]<0) {
        int u=up[x], v=dn[x];
        LL p=tr[u].val, q=tr[v].val;
        ans+=p+q-2*dis[x];
        up[x]=merge(tr[up[x]].lc, tr[up[x]].rc);
        dn[x]=merge(tr[dn[x]].lc, tr[dn[x]].rc);
        up[x]=merge(up[x], add_n(2*dis[x]-q));
        dn[x]=merge(dn[x], add_n(2*dis[x]-p));
    }
}

int main() {
    int n=read();
    for(int i=1, x, y, d; i<n; ++i) {
        x=read(), y=read(), d=read();
        add_e(x, y, d); add_e(y, x, d);
    }
    int s=0;
    for(int i=1; i<=n; ++i) {
        a[i]=read(), a[i]-=read();
        if(a[i]<0) s+=-a[i];
    }
    dfs(1, 0);
    sol(1, 0);
    printf("%lld", ans+M*s);
    return 0;
}

詳細信息

Test #1:

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

Test #2:

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

Test #3:

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

Test #4:

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

Test #5:

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

Test #6:

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

Test #7:

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

Test #8:

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

Test #9:

score: 0
Accepted
time: 25ms
memory: 18684kb

Test #10:

score: 0
Accepted
time: 47ms
memory: 31184kb

Test #11:

score: 0
Accepted
time: 82ms
memory: 33904kb

Test #12:

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

Test #13:

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

Test #14:

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

Test #15:

score: 0
Accepted
time: 1ms
memory: 1980kb

Test #16:

score: 0
Accepted
time: 1ms
memory: 4028kb

Test #17:

score: 0
Accepted
time: 1ms
memory: 4028kb

Test #18:

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

Test #19:

score: 0
Accepted
time: 11ms
memory: 9644kb

Test #20:

score: 0
Accepted
time: 85ms
memory: 57244kb

Test #21:

score: 0
Accepted
time: 31ms
memory: 12076kb

Test #22:

score: 0
Accepted
time: 37ms
memory: 12064kb

Test #23:

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

Test #24:

score: 0
Accepted
time: 18ms
memory: 8688kb

Test #25:

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

Test #26:

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

Test #27:

score: 0
Accepted
time: 44ms
memory: 32160kb

Test #28:

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

Test #29:

score: 0
Accepted
time: 61ms
memory: 40060kb

Test #30:

score: 0
Accepted
time: 188ms
memory: 95164kb

Test #31:

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

Test #32:

score: 0
Accepted
time: 64ms
memory: 45908kb

Test #33:

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

Test #34:

score: 0
Accepted
time: 350ms
memory: 74292kb

Test #35:

score: 0
Accepted
time: 136ms
memory: 40836kb

Test #36:

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

Test #37:

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

Test #38:

score: -100
Runtime Error