全是0,求调
  • 板块灌水区
  • 楼主Sp6kw
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/7/20 12:48
  • 上次更新2024/7/20 14:13:12
查看原帖
全是0,求调
611118
Sp6kw楼主2024/7/20 12:48
#include <iostream>
#include <climits>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;

const int MAXN = 5e5 + 5;
const int INF = INT_MAX;

struct Node {
	int to, degree;
	bool operator <(const Node a) const {
		return degree > a.degree;
	}
};

int n, m, k;
int s, t;
int dist[MAXN];
bool vis[MAXN];
vector<Node> e[MAXN];
priority_queue<Node> q;

void add(int a, int b, int c = 0) {
	e[a].push_back({b, c});
}

void dij() {
	for (int i = 1; i <= n; i++) {
		dist[i] = INF;
	}
	dist[s] = 0;
	q.push({s, dist[s]});
	while (!q.empty()) {
		Node u = q.top();
		q.pop();
		if (vis[u.to]) continue;
		vis[u.to] = 1;
		for (auto i : e[u.to]) {
			if (dist[i.to] > dist[u.to] + i.degree) {
				dist[i.to] = dist[u.to] + i.degree;
				if (!vis[i.to]) q.push({i.to, dist[i.to]});
			}
		}
	}
}

int main() {
	cin >> n >> m >> k;
	cin >> s >> t;
	++s, ++t;
	for (int i = 1; i <= m; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a++, b++;
		add(a, b, c);
		add(b, a, c);
		for (int j = 1; j <= k; j++) {
			add(a + (j - 1) * n, b + j * n);
			add(b + (j - 1) * n, a + j * n);

			add(a + j * n, b + j * n, c);
			add(b + j * n, a + j * n, c);
		}
	}
	for (int i = 1; i <= k; i++) {
		add(t + i * n, t + (i + 1) * n);
	}
	dij();
	cout << dist[t + (k + 1) * n] << endl;
	return 0;
}

P4568

2024/7/20 12:48
加载中...