TRZ_2007 @ 2018-12-31 16:24:28
本机测试通过
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define N 100000
int n,m,maxx=1e9,minn,t,z,i,j,k,x,y;
long long ans;
bool flag[N];
int c[N],d[N];
int f1[N][N],f2[N][N];
int read()
{
int x=0,p=1;
char c;
c=getchar();
while(c<'0'||c>'9')
{
if(c=='-')
p=-1;
c=getchar();
}
while(c>='0'&&c<='9')
{
x=x*10+c-'0';
c=getchar();
}
return x*p;
}
int main()
{
n=read();
m=read();
memset(f1,0x7f,sizeof(f1));
memset(f2,0x7f,sizeof(f2));
memset(c,0x7f,sizeof(c));
memset(d,0x7f,sizeof(d));
maxx=f1[0][0];
for(i=1;i<=m;i++)
{
x=read();
y=read();
z=read();
f1[x][y]=min(f1[x][y],z);
f2[y][x]=min(f2[y][x],z);
}
memset(flag,false,sizeof(flag));
for(i=1;i<=n;i++)
c[i]=f1[1][i];
flag[1]=true;
c[1]=0;
for(i=1;i<=n-1;i++)
{
minn=maxx;
k=0;
for(j=1;j<=n;j++)
if((!flag[j])&&(c[j]<minn))
{
minn=c[j];
k=j;
}
if(k==0) break;
flag[k]=true;
for(j=1;j<=n;j++)
{
if(c[k]+f1[k][j]<c[j])
c[j]=c[k]+f1[k][j];
}
}
memset(flag,false,sizeof(flag));
for(i=1;i<=n;i++)
d[i]=f2[1][i];
flag[1]=true;
d[1]=0;
for(i=1;i<=n-1;i++)
{
minn=maxx;
k=0;
for(j=1;j<=n;j++)
if((!flag[j])&&(d[j]<minn))
{
minn=d[j];
k=j;
}
if(k==0) break;
flag[k]=true;
for(j=1;j<=n;j++)
if(d[k]+f2[k][j]<d[j])
d[j]=d[k]+f2[k][j];
}
for(i=1;i<=n;i++)
ans+=c[i]+d[i];
printf("%lld",ans);
}
by 豌豆射手皮0608 @ 2018-12-31 16:31:34
可能是你谷评测姬炸了233
by Heartlessly @ 2018-12-31 16:33:16
@TRZ_2007 memset好像要cstring库吧
by 狂犇 @ 2018-12-31 16:34:13
显示:源文件未编译
by TRZ_2007 @ 2018-12-31 16:47:45
@xuxing 加了啊,C的头