QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#751036 | #2429. Conquer The World | GotoHiotori | WA | 211ms | 43324kb | C++14 | 1.4kb | 2024-11-15 16:49:23 | 2024-11-15 16:49:23 |
Judging History
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