QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#751036#2429. Conquer The WorldGotoHiotoriWA 211ms43324kbC++141.4kb2024-11-15 16:49:232024-11-15 16:49:23

Judging History

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

  • [2024-11-15 16:49:23]
  • 评测
  • 测评结果:WA
  • 用时:211ms
  • 内存:43324kb
  • [2024-11-15 16:49:23]
  • 提交

answer

#include<stdio.h>
#include<algorithm>
#include<assert.h>
struct{
    int v,w,nxt;
}edge[500000];
struct{
    int u,v;
}a[5000*5000+1];
int head[250001],x[250001],y[250001];
long long dis[5001][5001];
void dfs(int u,int f,int s){
    for(int i=head[u];i;i=edge[i].nxt)
        if(edge[i].v!=f)
            dis[s][edge[i].v]=dis[s][u]+edge[i].w,dfs(edge[i].v,u,s);
}
int main(){
    int n;
    scanf("%d",&n);
    assert(n<=2000);
    for(int i=1,u,v,w;i<n;++i)scanf("%d%d%d",&u,&v,&w),edge[i*2-1]={v,w,head[u]},edge[i*2]={u,w,head[v]},head[u]=i*2-1,head[v]=2*i;
    for(int i=1;i<=n;++i)scanf("%d%d",x+i,y+i);
    for(int i=1;i<=n;++i)
        dfs(i,0,i);
    for(int i=1;i<=n;++i)
        for(int j=1;j<=n;++j)
            a[(i-1)*n+j]={i,j};
    std::sort(a+1,a+n*n+1,[](const auto&x,const auto&y){return dis[x.u][x.v]<dis[y.u][y.v];});
    long long sum=0;
    for(int i=1;i<=n*n;++i)
        if(x[a[i].u]<y[a[i].u]&&x[a[i].v]>y[a[i].v]){
            if(x[a[i].u]+x[a[i].v]>=y[a[i].u]+y[a[i].v]){
                sum+=dis[a[i].u][a[i].v]*(y[a[i].u]-x[a[i].u]);
                x[a[i].v]-=y[a[i].u]-x[a[i].u],x[a[i].u]=y[a[i].u];
            }else{
                sum+=dis[a[i].u][a[i].v]*(x[a[i].v]-y[a[i].v]);
                x[a[i].u]+=x[a[i].v]-y[a[i].v],x[a[i].v]=y[a[i].v];
            }
        }
    printf("%lld",sum);
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 5728kb

Test #2:

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

Test #3:

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

Test #4:

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

Test #5:

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

Test #6:

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

Test #7:

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

Test #8:

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

Test #9:

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

Test #10:

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

Test #11:

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

Test #12:

score: -100
Wrong Answer
time: 211ms
memory: 43324kb