P4568 JLOI2011 飞行路线 - 洛谷 (luogu.com.cn)
即有 K 次免费走边的机会。

cpp
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
struct node {
int x;
LL c;
};
vector<node> G[N];
LL d[N];
int st, ed;
bool operator<(node na, node nb) {
return na.c > nb.c;
}
priority_queue<node> Q;
bool v[N];
void dijkstra() {
memset(d, 0x3f, sizeof(d));
memset(v, 0, sizeof(v));
Q.push({st, 0}); d[st] = 0;
while (!Q.empty()) {
node no = Q.top(); Q.pop();
if (v[no.x]) {
continue;
}
v[no.x] = 1;
for (node i : G[no.x]) {
if (d[i.x] > d[no.x] + i.c) {
d[i.x] = d[no.x] + i.c;
Q.push({i.x, d[i.x]});
}
}
}
}
int main () {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, K;
cin >> n >> m >> K;
cin >> st >> ed;
for (int i = 1; i <= m; i ++) {
int x, y; LL c;
cin >> x >> y >> c;
G[x].push_back({y, c});
G[y].push_back({x, c});
for (int j = 1; j <= K; j ++) {
G[x + j * n].push_back({y + j * n, c});
G[y + j * n].push_back({x + j * n, c});
G[x + (j - 1) * n].push_back({y + j * n, 0});
G[y + (j - 1) * n].push_back({x + j * n, 0});
}
}
for (int j = 1; j <= K; j ++) {
G[ed + (j - 1) * n].push_back({ed + j * n, 0});
}
dijkstra();
cout << d[ed + K * n] << "\n";
return 0;
}
AT_abc132_e ABC132E Hopscotch Addict - 洛谷 (luogu.com.cn)
这就是强制要求走三的倍数条边。不打了。