WA on #3求条
查看原帖
WA on #3求条
683212
Henly_Z楼主2024/10/15 15:13
#include<bits/stdc++.h>
using namespace std;
constexpr int N = 500005;
int deg[N][20],n,m,k,s,t;
struct Node {
	int v , w , deg;
	friend bool operator < (Node a,Node b){
		return a.w > b.w;
	}
};
vector<Node> G[N];
void bfs(int cur) {
	priority_queue<Node> q;
	q.push({cur,0,0});
	deg[cur][0] = 0;
	while(!q.empty()) {
		int u = q.top().v;
		int w = q.top().w;
		int deg1 = q.top().deg;
		q.pop();
//		cout << u << " " << deg1 << " 1" <<endl;
		for(auto v : G[u]) {
//			cout << v.v << " " << v.deg << " " << v.w << endl;
			if(deg[v.v][deg1] > w + v.w) {
//				cout << v.v << endl;
				deg[v.v][deg1] = w + v.w;
				q.push({v.v,w+v.w,deg1}	);
			}
			if(deg1 < k && deg[v.v][deg1 + 1] > w) {
//				cout << v.v << " 1" << endl;
				deg[v.v][deg1 + 1] = w;
				q.push({v.v,w,deg1 + 1});
			}
		}
	}
}
signed main() {

	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout.tie(0);
	cin >> n >> m >> k;
	cin >> s >> t;
	for(int i = 1 ; i <= m ; i++) {
		int u , v , w;
		cin >> u >> v >> w;
		G[u].push_back({v,w,0});
		G[v].push_back({u,w,0});
	}
	memset(deg,0x3f,sizeof(deg));
	bfs(s);
	int minn = 1000000;
//	for(int i = 0 ; i <= n ; i++){
//		for(int j = 0 ; j <= n ; j++){
//			cout << deg[i][j] << " " ;
//		}
//		cout << endl;
//	}
	for(int i = 0 ; i <= k ; i++) {
		minn = min(minn , deg[t][i]);
	}
	cout << minn;
}
2024/10/15 15:13
加载中...