/ Randle /

记录详情

Time Exceeded


  
# 状态 耗时 内存占用
#1 Time Exceeded ≥1006ms ≥256.0 KiB
#2 Time Exceeded ≥1004ms ≥256.0 KiB
#3 Time Exceeded ≥1005ms ≥268.0 KiB
#4 Time Exceeded ≥1003ms ≥380.0 KiB
#5 Time Exceeded ≥1003ms ≥256.0 KiB
#6 Time Exceeded ≥1005ms ≥384.0 KiB
#7 Time Exceeded ≥1006ms ≥372.0 KiB
#8 Time Exceeded ≥1007ms ≥256.0 KiB
#9 Time Exceeded ≥1007ms ≥384.0 KiB
#10 Time Exceeded ≥1003ms ≥384.0 KiB

代码

#include<bits/stdc++.h>
#define maxn 1005
#define maxm 100005
using namespace std;
struct edge
{
	int to,next,len;
	double p;
}a[maxm];
int pre[maxn];
int n,m,tot;
int v[maxn];
int first[maxn];
int exist[maxm];
int dis[maxn];
queue <int> que;
inline const void read(int &a)
{
	a=0;
	char c=getchar();
	while(c<'0'||c>'9') c=getchar();
	while(c<='9'&&c>='0')
	{
		a=(a<<1)+(a<<3)+c-'0';
		c=getchar(); 
	}
} 
void add_edge(int x,int y,int z,double p)
{
	a[++tot].to=y;
	a[tot].len=z;
	a[tot].p=p;
	a[tot].next=first[x];
	first[x]=tot;
}
int spfa()
{
	memset(dis,-1,sizeof(dis));
	dis[1]=0;
	que.push(1);
	v[1]=1;
	while(!que.empty())
	{
		int x=que.front();
		que.pop();
		for(int i=first[x];i!=-1;i=a[i].next)
		{
			int vv=a[i].to;
			//cout<<"vv="<<vv<<' ';
			if(exist[i]&&(dis[vv]==-1||dis[x]+a[i].len<dis[vv]))
			{
				//cout<<"vv="<<vv<<endl;
				dis[vv]=dis[x]+a[i].len;
				pre[vv]=i;
				if(!v[vv])
				{
					v[vv]=1;
					que.push(vv);
				}
			}
		}
		v[x]=0;
	}
	//cout<<"\ndis["<<n<<"]="<<dis[n]<<endl;
	if(dis[n]>dis[0])
	return dis[n];
	else return 0;
}
int main()
{
	freopen("in.txt","r",stdin);
	int x1,x2,x3;
	double y;
	read(n);read(m);
	memset(first,-1,sizeof(first));
	memset(exist,1,sizeof(exist));
	memset(pre,-1,sizeof(pre));
	for(int i=1;i<=m;i++)
	{
		read(x1);read(x2);read(x3);
		cin>>y;
		add_edge(x1,x2,x3,y);
		add_edge(x2,x1,x3,y);
	}
	int k=spfa();
	double temp=0;
	if(k==0)
	{
		cout<<"0.0000000"<<endl;
		return 0;
	}
	//cout<<"k="<<k<<endl;
	for(int i=1;i<=tot;i+=2)
	{
		temp+=a[i].p;
		//cout<<"p="<<a[i].to<<" temp="<<temp<<endl;
	}
	double ans=(double)k*(1-temp);
	//cout<<"ans="<<ans<<endl;
	for(int i=1;i<=tot;i+=2)
	{
		exist[i]=0;exist[i^1]=0;
		int k=spfa();
		ans+=(double)k*a[i].p;
		//cout<<"p="<<a[i].p<<" k="<<k<<" ans="<<ans<<endl;
		exist[i]=1;exist[i^1]=1;
	}
	printf("%.7f\n",ans);
	return 0;
}

信息

递交者
类型
递交
题目
从中国到阿布拉斯基索沃尔朗特乎斯德麦尔维(原创)
题目数据
下载
语言
C++
递交时间
2017-11-06 20:36:46
评测时间
2017-11-06 20:40:51
评测机
分数
0
总耗时
≥10053ms
峰值内存
≥384.0 KiB