求调分层图,只有10pts
查看原帖
求调分层图,只有10pts
1053595
_Warfarin_楼主2024/4/10 15:12
#include <bits/stdc++.h>

#define ll long long
#define io cin.tie(0),cout.tie(0),ios::sync_with_stdio(false)
#define ri register int
#define lb long double

using namespace std;
const int N = 214514;
const int M = 5500050;
struct node
{
	int ver, nex, edge;
	
} point[M];
int head[N], dis[N];
bool vis[N];
int n, m, k, s, t;
typedef pair <int, int > qwq;
priority_queue<qwq> q;
int tot = 0;
inline void add(int x, int y, int z)
{
	point[++tot].ver = y;
	point[tot].edge = z;
	point[tot].nex = head[x];
	head[x] = tot;
}
inline void dijkstra(int s)
{
	memset(dis, 0x3f, sizeof(dis));
	dis[s] = 0;
	q.push({0, s});
	while (q.size())
	{
		auto owo = q.top();
		int w = owo.second;
		q.pop();
		if (vis[w])
			continue;
		vis[w] = true;
		for (ri i = head[w]; i ; i = point[i].nex)
		{
			int x = point[i].ver;
			int y = point[i].edge;
			if (dis[x] > max(dis[w], y))
			{
				dis[x] = max(dis[w], y);
				q.push({dis[x], x});
			}
		}
	}
}
int main()
{
	io;
	cin >> n >> m >> k;
	int s, e;
	s = 1, e = n;
	for (ri i = 1; i <= m; i++)
	{
		int x, y, z;
		cin >> x >> y >> z;
		add(x, y, z);
		add(y, x, z);
		for (ri j = 1; j <= k; j++)
		{
			add(x + (j - 1)*n, y + j * n, 0);
			add(y + (j - 1)*n, x + j * n, 0);
			add(x + j * n, y + j * n, z);
			add(y + j * n, x + j * n, z);
		}
	}
	for (ri i = 1; i <= k; i++)
		add(t + (i - 1)*n, t + i * n, 0);
	dijkstra(s);
	dis[e + k * n] == 0x3f3f3f3f ? cout << -1 << endl : cout << dis[e + k * n] << endl;
	return 0;
}
2024/4/10 15:12
加载中...