题意

题目链接

Sol

分层图+最短路

建\(k+1\)层图,对于边\((u, v, w)\),首先在本层内连边权为\(w\)的无向边,再各向下一层对应的节点连边权为\(0\)的有向边

如果是取最大最小值的话可以考虑二分答案+最短路

// luogu-judger-enable-o2
// luogu-judger-enable-o2
#include<bits/stdc++.h>
#define Pair pair<int, int>
#define MP make_pair
#define fi first
#define se second
using namespace std;
const int MAXN = 2e5 + 10;
inline int read() {
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int N, M, K, S, T, TT, vis[MAXN], dis[MAXN];
vector<Pair> v[MAXN];
void AddEdge(int x, int y, int z, int f) {
v[x].push_back(MP(y, z));
if(f) v[y].push_back(MP(x, z));
}
void Dij(int s) {
priority_queue<Pair> q; q.push(MP(0, s));
memset(dis, 0x3f, sizeof(dis)); dis[s] = 0;
while(!q.empty()) {
if(vis[q.top().se]) {q.pop(); continue;}
int p = q.top().se; q.pop(); vis[p] = 1;
for(int i = 0; i < v[p].size(); i++) {
int to = v[p][i].fi, w = v[p][i].se;
if(dis[to] > dis[p] + w) dis[to] = dis[p] + w, q.push(MP(-dis[to], to));
}
}
}
int main() {
// freopen("a.in", "r", stdin);
N = read(); M = read(); K = read(); S = read() + 1; T = read() + 1; TT = N * (K + 1) + 1;
for(int i = 1; i <= M; i++) {
int u = read() + 1, v = read() + 1, w = read();
for(int j = 0; j < K; j++) {
AddEdge(j * N + u, j * N + v, w, 1);
AddEdge(j * N + u, (j + 1) * N + v, 0, 0);
AddEdge(j * N + v, (j + 1) * N + u, 0, 0);
}
AddEdge(N * K + u, N * K + v, w, 1);
}
for(int j = 0; j <= K; j++) AddEdge(j * N + T, TT, 0, 0);
Dij(S);
printf("%d", dis[TT]);
return 0;
}

最新文章

  1. PHP数组函数总结
  2. HA简介以及HBase简介
  3. JS cookie的使用
  4. QT对话框模式与非模式
  5. Spring Transaction属性之Propagation
  6. android_launcher的源码详细分析
  7. linux学习历程
  8. python有三种导入模块的方法(转)
  9. spring jdbc踩坑日记,new JdbcTemplate 为null导致UserDao一直为null
  10. blog写作心得体会
  11. samba企业级实战应用详解-技术流ken
  12. HDU1846 Brave Game
  13. SpringBoot实现热部署(修改class不需要重启)
  14. python保存文件到数据库
  15. 博客搬家了qwq
  16. Ubuntu telnet
  17. 在NGUI中高效优化UIScrollView之UIWrapContent的简介以及使用
  18. 修改kvm虚拟机镜像大小
  19. EntityFramework 学习资料
  20. 类型:Oracle;问题:oracle 时间加减;结果:ORACLE 日期加减操作

热门文章

  1. Chrome打开网页都提示Flash Player因过期而遭到阻止
  2. SQL语句exists用法
  3. Dijkstra实现最短路径
  4. Mathematica多元隐函数作图
  5. 根据word模版导入word中用户填写的数据
  6. 与native交互时会出现的问题
  7. (转)python标准库中socket模块详解
  8. Oracle Net Configuration(监听程序和网络服务配置)
  9. Git学习系列之一些常用的Git命令收录更新ing
  10. 005-C3P0连接池配置文件模板