QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#751020#2429. Conquer The WorldGotoHiotoriWA 224ms40604kbC++141.4kb2024-11-15 16:46:432024-11-15 16:46:43

Judging History

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

  • [2024-11-15 16:46:43]
  • 评测
  • 测评结果:WA
  • 用时:224ms
  • 内存:40604kb
  • [2024-11-15 16:46:43]
  • 提交

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<=5000);
    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;
}

Details

Test #1:

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

Test #2:

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

Test #3:

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

Test #4:

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

Test #5:

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

Test #6:

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

Test #7:

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

Test #8:

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

Test #9:

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

Test #10:

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

Test #11:

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

Test #12:

score: -100
Wrong Answer
time: 224ms
memory: 40604kb