0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-09 23:18:47 +00:00

2662. [BeiJing wc2012]冻结

https://darkbzoj.cc/submission/191601
This commit is contained in:
Baoshuo Ren 2022-05-13 19:34:52 +08:00
parent 21f4c7d755
commit 59210c472b
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

73
BZOJ/2662/2662.cpp Normal file
View File

@ -0,0 +1,73 @@
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 55;
int n, m, k, dist[N << 6];
std::vector<std::pair<int, int>> g[N << 6];
bool vis[N << 6];
void dijkstra() {
memset(dist, 0x3f, sizeof(dist));
std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int>>, std::greater<std::pair<int, int>>> q;
q.push(std::make_pair(0, 1));
dist[1] = 0;
while (!q.empty()) {
auto t = q.top();
q.pop();
if (vis[t.second]) continue;
for (auto e : g[t.second]) {
int v = e.first,
w = e.second;
if (dist[v] > t.first + w) {
dist[v] = t.first + w;
q.push(std::make_pair(dist[v], v));
}
}
vis[t.second] = true;
}
}
int main() {
std::ios::sync_with_stdio(false);
cin >> n >> m >> k;
for (int i = 1, u, v, w; i <= m; i++) {
cin >> u >> v >> w;
g[u].push_back(std::make_pair(v, w));
g[v].push_back(std::make_pair(u, w));
for (int j = 1; j <= k; j++) {
g[u + (j - 1) * n].push_back(std::make_pair(v + j * n, w >> 1));
g[v + (j - 1) * n].push_back(std::make_pair(u + j * n, w >> 1));
g[u + j * n].push_back(std::make_pair(v + j * n, w));
g[v + j * n].push_back(std::make_pair(u + j * n, w));
}
}
for (int i = 0; i <= k; i++) {
g[i * n].push_back(std::make_pair(i * n + n, 0));
}
dijkstra();
cout << dist[n * k + n] << endl;
return 0;
}