题目大意:有$n(2\leqslant n\leqslant200)$个城市,$m(1\leqslant m\leqslant40000)$条无向边,你要找$T(1\leqslant T\leqslant200)$条从城市$1$到城市$n$的路,使得最长的边的长度最小,边不能重复用。

题解:二分答案,跑网络流,每条边边权为$1$,看最大流是否比$T$大。(实测我常数不能再大的$HLPP$跑的比$ISAP$慢,所以就放$ISAP$了,其实都是板子)

卡点:

C++ Code:

#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#define maxn 210
#define maxm 40010
const int inf = 0x3f3f3f3f;
inline int min(int a, int b) {return a < b ? a : b;}
inline int max(int a, int b) {return a > b ? a : b;}
namespace Network_Flow {
int st, ed, MF, n;
int head[maxn], cnt = 2;
struct Edge {
int to, nxt, w;
} e[maxm << 1];
inline void addE(int a, int b, int c) {
e[cnt] = (Edge) {b, head[a], c}; head[a] = cnt;
e[cnt ^ 1] = (Edge) {a, head[b], c}; head[b] = cnt ^ 1;
cnt += 2;
}
int GAP[maxn], d[maxn];
int last[maxn];
int q[maxn], h, t;
inline void init() {
GAP[d[ed] = 1] = 1;
for (int i = 1; i <= n; i++) last[i] = head[i];
q[h = t = 0] = ed;
while (h <= t) {
int u = q[h++];
for (int i = head[u]; i; i = e[i].nxt) {
int v = e[i].to;
if (!d[v]) {
d[v] = d[u] + 1;
GAP[d[v]]++;
q[++t] = v;
}
}
}
}
int dfs(int u, int low) {
if (!low || u == ed) return low;
int w, res = 0;
for (int &i = last[u]; i; i = e[i].nxt) {
int v = e[i].to;
if (d[u] == d[v] + 1) {
w = dfs(v, min(low, e[i].w));
res += w, low -= w;
e[i].w -= w, e[i ^ 1].w += w;
if (!low) return res;
}
}
if (!(--GAP[d[u]])) d[st] = n + 1;
++GAP[++d[u]], last[u] = head[u];
return res;
}
inline void ISAP(int S, int T) {
st = S, ed = T;
init();
while (d[st] <= n) MF += dfs(st, inf);
}
inline void clear() {
memset(head, 0, sizeof head); cnt = 2;
memset(GAP, 0, sizeof GAP);
memset(d, 0, sizeof d);
MF = 0;
}
}
#define read() R::READ()
#include <cctype>
namespace R {
int x;
#ifdef ONLINE_JUGER
#define M 1 << 25
char op[M], *ch;
inline void init() {fread(ch = op, 1, M, stdin);}
inline int READ() {
while (isspace(*ch)) ch++;
for (x = *ch & 15, ch++; isdigit(*ch); ch++) x = x * 10 + (*ch & 15);
return x;
}
#undef M
#else
char ch;
inline int READ() {
ch = getchar();
while (isspace(ch)) ch = getchar();
for (x = ch & 15, ch = getchar(); isdigit(ch); ch = getchar()) x = x * 10 + (ch & 15);
return x;
}
#endif
}
int n, m, T, M;
int u[maxm], v[maxm], w[maxm];
inline bool check(int mid) {
for (int i = 1; i <= m; i++) if (w[i] <= mid) Network_Flow::addE(u[i], v[i], 1);
Network_Flow::ISAP(1, n);
if (Network_Flow::MF >= T) return true;
return false;
}
int main() {
#ifdef ONLINE_JUGER
R::init();
#endif
n = read(), m = read(), T = read();
Network_Flow::n = n;
for (int i = 1; i <= m; i++) {
u[i] = read(), v[i] = read(), w[i] = read();
M = max(M, w[i]);
}
int l = 1, r = M, ans = -1;
while (l <= r) {
int mid = l + r >> 1;
if (check(mid)) {
r = mid - 1;
ans = mid;
} else l = mid + 1;
if (l <= r) Network_Flow::clear();
}
printf("%d\n", ans);
return 0;
}

  

最新文章

  1. IT人创业之融资方式 - 创业与投资系列文章
  2. hive外部表的建立与数据匹配
  3. MySQL 中隔离级别 RC 与 RR 的区别
  4. zabbix监控模式、分布式、自动化
  5. python3中urllib2的问题
  6. linux命令:cp
  7. 思科ASA系列防火墙配置手册
  8. 指尖下的js ——多触式web前端开发之一:对于Touch的处理
  9. Java数据结构漫谈-Stack
  10. 关于淘宝的数据来源,针对做淘宝客网站的淘宝api调用方法
  11. python 机器学习 K-近邻算法
  12. POSIX标准 库文件
  13. gdb remote 使用
  14. tensorflow c/c++库使用方法
  15. PHP类的继承
  16. 转:[C# 开发技巧]如何防止程序多次运行
  17. input框和文字对齐问题
  18. PostThreadMessage
  19. python求100以内素数
  20. Python初学者第二十二天 函数进阶(1)

热门文章

  1. 一道SQL面试题——表行列数据转换(表转置)
  2. PHP Laravel 5.4 环境搭建
  3. 洛谷 U45568 赌神:决斗
  4. CentOS(Linux)安装KETTLE教程 并配置执行定时任务
  5. go学习笔记-函数
  6. ProxySQL初体验
  7. Linux-Qt Quick学习1-Hello world
  8. 在Kotlin编写RecyclerView适配器(KAD 16)
  9. 第十九章 Python os模块,pathlib 判断文件是目录还是文件
  10. python终极篇 --- django 初识