测试点1自己电脑上输入in的答案与out一模一样,但是交上去这个点wa了
查看原帖
测试点1自己电脑上输入in的答案与out一模一样,但是交上去这个点wa了
550696
向来萧瑟处楼主2021/8/23 22:34
#include<bits/stdc++.h>
using namespace std;
#define MAX 100100
#define inf 98765432
int n,m,u[MAX<<1],v[MAX<<1],w[MAX<<1],first[1010],next[MAX<<1],dis[1010],book[1010];
int sec[1010],last[MAX<<1],len[1010],phone[1010];
int read()
{
	char y;
	int x=0;
	y=getchar();
	while('0'<=y && y<='9')
	{
		x=x*10+y-'0';
		y=getchar();
	}
	return x;
}
int main()
{
	n=read(),m=read();
	for(int i=1;i<=n;i++)	first[i]=-1,sec[i]=-1,dis[i]=inf,len[i]=inf;
	dis[1]=0;len[1]=0;
	for(int i=1;i<=m;i++)
	{
		u[i]=read();v[i]=read();w[i]=read();
		next[i]=first[u[i]];
		first[u[i]]=i;
		last[i]=sec[v[i]];
		sec[v[i]]=i;
	}
	int mi,cur,edge;
	for(int i=1;i<n;i++)
	{
		mi=inf;
		for(int j=1;j<=n;j++)
		{
			if(!book[j] && dis[j]<mi)
			{
				mi=dis[j];
				cur=j;
			}
		}
		book[cur]=1;
		edge=first[cur];
		while(edge)
		{
			dis[v[edge]]=min(dis[v[edge]],dis[cur]+w[edge]);
			edge=next[edge];
		}
		mi=inf;	
		for(int j=1;j<=n;j++)
			if(!phone[j] && len[j]<mi)
			{
				mi=len[j];
				cur=j;	
			}
		phone[cur]=1;
		edge=sec[cur];
		while(edge)
		{
			len[u[edge]]=min(len[u[edge]],len[cur]+w[edge]);
			edge=last[edge];
		}
	}
	long long s=0;
	for(int i=2;i<=n;i++)
		s+=(dis[i]+len[i]);
	printf("%lld\n",s);
	return 0;
}

测试点1显示第一行第一列read 2 但是我运行数据结果是818 数据:50 250 41 49 10 13 15 5 50 14 7 27 12 3 18 19 6 34 23 10 29 33 9 20 42 9 10 45 10 17 2 6 36 47 3 12 16 4 35 36 10 50 13 6 39 48 10 18 46 8 10 9 9 31 46 8 12 1 5 36 7 4 32 2 6 38 10 1 40 49 6 30 35 3 48 20 6 20 28 1 43 21 1 12 20 1 15 14 5 35 6 8 34 9 10 20 19 8 43 41 10 33 28 10 23 14 1 8 33 5 39 18 9 41 7 5 22 29 2 27 5 1 24 36 6 50 27 1 49 14 2 21 14 10 26 37 8 43 13 8 8 45 2 7 38 1 36 12 9 19 27 2 37 33 10 39 45 7 41 43 8 12 16 3 22 34 7 23 33 6 44 49 3 44 15 6 12 13 9 13 25 9 27 42 5 13 44 8 27 47 10 25 36 2 38 4 3 10 14 3 11 46 7 13 44 7 1 5 3 1 22 3 17 14 1 19 22 6 46 9 3 22 13 2 19 11 6 30 3 6 26 29 7 29 49 6 29 22 9 25 49 5 38 4 8 17 7 6 13 20 1 26 25 1 44 16 1 44 11 2 7 19 3 12 21 5 42 13 9 35 3 8 4 18 7 20 19 2 41 40 10 14 50 6 3 34 3 33 5 1 4 12 9 38 16 4 12 41 5 25 45 8 34 30 1 11 21 7 3 5 5 44 3 2 27 1 1 35 22 1 32 33 10 19 5 6 47 30 10 37 47 7 42 15 10 7 2 1 31 36 6 21 38 2 44 46 5 9 37 10 49 17 4 13 40 5 16 8 3 7 31 7 33 30 4 14 47 5 22 10 7 46 9 8 11 45 3 37 50 10 1 40 3 18 43 7 39 7 4 47 2 2 45 35 2 12 38 4 23 40 4 34 24 7 5 30 9 20 28 8 32 41 1 37 48 3 19 23 8 28 20 2 41 31 10 35 7 7 42 41 7 48 27 5 48 18 4 4 45 5 3 39 4 7 49 9 8 28 2 26 50 1 37 24 10 49 34 2 9 7 5 33 30 10 18 26 9 10 42 5 27 24 7 27 37 5 27 45 10 36 29 2 40 28 9 14 15 5 20 4 5 31 30 9 1 11 2 29 2 10 30 39 5 32 13 6 23 31 1 33 16 10 29 46 8 50 28 2 36 17 4 36 15 7 25 30 1 34 40 3 43 5 8 47 5 1 49 13 5 21 36 4 2 19 10 39 45 8 3 11 3 22 3 10 17 37 6 25 10 1 6 50 8 50 2 9 38 16 9 45 5 6 45 18 10 9 49 1 29 33 8 18 50 2 35 27 10 42 27 2 13 7 6 20 46 6 46 22 4 1 28 8 30 27 4 15 10 9 45 18 1 9 8 6 36 47 2 49 7 10 27 33 2 22 39 10 47 7 6 34 41 1 27 45 7 5 49 3 42 37 3 45 31 3 2 26 7 50 49 5 37 14 7 42 46 5 6 25 7 34 32 7 29 18 5 26 14 8 30 10 4 4 36 3 9 17 6 36 7 3 23 17 10 29 6 4 27 34 9 9 38 7 29 34 6 32 11 8 14 27 2 39 31 8 10 41 6 22 39 4 46 31 4 24 44 9 8 36 4 36 44 3 8 21 8 22 24 1 30 38 4 22 41 7 41 37 9 41 31 9 33 30 10 36 9 5 43 14 1 20 10 4

2021/8/23 22:34
加载中...