40pts WA 各位巨佬给看看吧
查看原帖
40pts WA 各位巨佬给看看吧
49677
miserExist楼主2021/10/16 18:46

不太明白分层图哪里写炸了,永远40pts

#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> PII;
#define int long long
#define debug cout<<"!error!";

const int M = 610,inf = 0x3f3f3f3f;


struct node
{
	int u, rate;
	double T;
	node(int uu, double tt, int rr)
	{
		u = uu, T = tt, rate = rr;
	}
	const bool operator < (const node rhs) const 
	{
		if(T == rhs.T)
		{
			return rate < rhs.rate;
		}
		else return T > rhs.T;
	}
};
int vis[M][M];
int n,m,D;
PII path_[M][M];
int h[M], e[M], ne[M], idx, limit_rate[M], length[M];
double T[M][M];
void add(int a, int b, int c, int d)
{
	e[idx] = b;
	ne[idx] = h[a];
	limit_rate[idx] = c;
	length[idx] = d;
	h[a] = idx ++;
}
void dij(int s)
{
	T[s][70] = 0;
	priority_queue<node> q;
	//vis[s][70] = 1;
	q.push(node(s,0,70));
	while(!q.empty())
	{
		node t = q.top();
		q.pop();
		int u = t.u, speed = t.rate;
		double times = t.T;
		if(vis[u][speed]) continue;
		vis[u][speed] = 1;
		for(int i = h[u]; ~i; i = ne[i])
		{
			int y = e[i];
			int len = length[i];
			int lim = limit_rate[i];
			if(lim == 0)
			{
				double delta_T = ((double)len / (double)speed);
				if(T[y][speed] > T[u][speed] + delta_T)
				{
					T[y][speed] = T[u][speed] + delta_T;
					q.push(node(y, T[y][speed], speed));
					path_[y][speed] = make_pair(u, speed);
				}
			}
			else if(lim != 0)
			{
				double delta_T = ((double)len / (double)lim);
				if(T[y][lim] > T[u][speed] + delta_T)
				{
					T[y][lim] = T[u][speed] + delta_T;
					q.push(node(y, T[y][lim], lim));
					path_[y][lim] = make_pair(u, speed);
				}
			}
		}
	}
	return;
}
void print(int u, int rate)
{
	if(u == 0) 
	{
		printf("0 ");
		return;
	}
	print(path_[u][rate].first, path_[u][rate].second);
	printf("%lld ", u);
	return;
}
signed main()
{
	cin >> n >> m >> D;
	memset(h, -1, sizeof h);
	for(int i = 1; i <= m; i ++)
	{
		int a,b,c,d;
		scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
		add(a,b,c,d);
	}
	//memset(T, inf, sizeof T);
	for(int i = 0; i < n; i ++)
	{
		for(int j = 1; j <= 505; j ++)
		{
			T[i][j] = 1e9;
		}
	}
	dij(0);
	//double minn = 1e9;
	int start_rate = 0;
	T[D][start_rate] = 1e9;
	for(int i = 1; i <= 500; i ++)
	{
		if(T[D][start_rate] > T[D][i])
		{
			start_rate = i;
		}
	}

	print(D, start_rate);
	printf("\n");
	
	
	
	
	
	return 0;
}
2021/10/16 18:46
加载中...