P1401 城市(30分,正解网络流)
题目描述
N(2<=n<=200)个城市,M(1<=m<=40000)条无向边,你要找T(1<=T<=200)条从城市1到城市N的路,使得最长的边的长度最小,边不能重复用。
输入输出格式
输入格式:
第1行三个整数N,M,T用空格隔开。
第2行到P+1行,每行包括三个整数Ai,Bi,Li表示城市Ai到城市Bi之间有一条长度为Li的道路。
输出格式:
输出只有一行,包含一个整数,即经过的这些道路中最长的路的最小长度。
输入输出样例
7 9 2
1 2 2
2 3 5
3 7 5
1 4 1
4 3 1
4 5 7
5 7 1
1 6 3
6 7 3
5 正解是网络流。。。
所以就比较尴尬了。。
但是二分答案还是写出来了
等我哪天会了网络流一定回来A了这题。。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
const int MAXN=;
void read(int & n)
{
char c='+';int x=;bool flag=;
while(c<''||c>'')
{c=getchar();if(c=='-')flag=;}
while(c>=''&&c<='')
{x=x*+(c-);c=getchar();}
flag==?n=-x:n=x;
}
int n,m,t;
struct node
{
int u,v,w,nxt,use;
}edge[MAXN];
int head[MAXN];
int num=;
void add_edge(int x,int y,int z)
{
edge[num].u=x;
edge[num].v=y;
edge[num].w=z;
edge[num].nxt=head[x];
head[x]=num++;
}
int maxl=-,minl=0x7fff;
int vis[MAXN];
int map[][];
int have[][];
int bfs(int need)
{
queue<int>q;
q.push();
while(q.size()!=)
{
int p=q.front();
q.pop();
for(int i=head[p];i!=-;i=edge[i].nxt)
{
if(edge[i].w<=need&&have[edge[i].u][edge[i].v]==)
{
have[edge[i].u][edge[i].v]=;
have[edge[i].v][edge[i].u]=;
if(edge[i].v!=n)
q.push(edge[i].v);
vis[edge[i].v]++;
}
}
}
if(vis[n]>=t)
return ;
else
return ; }
int pd(int p)
{
memset(vis,,sizeof(vis));
memset(have,,sizeof(have));
if(bfs(p))
return ;
else
return ;
}
int main()
{
read(n);read(m);read(t);
for(int i=;i<=n;i++)
head[i]=-;
for(int i=;i<=m;i++)
{
int x,y,z;
read(x);read(y);read(z);
add_edge(x,y,z);
add_edge(y,x,z);
maxl=max(maxl,z);
minl=min(minl,z);
}
int l=minl,r=maxl;
while(l<r)
{
int mid=(l+r)>>;
if(pd(mid))
r=mid;
else l++;
}
printf("%d",l);
return ;
}
P1401 城市(30分,正解网络流)的更多相关文章
- Luogu P1401 城市(二分+网络流)
P1401 城市 题意 题目描述 N(2<=n<=200)个城市,M(1<=m<=40000)条无向边,你要找T(1<=T<=200)条从城市1到城市N的路,使得最 ...
- 「PKUWC 2018」随机算法 (第二版,正解做法)
上一版貌似是打了 O(3 ^ N) 暴力和 一条链的情况,得了60分.... 第一次做的时候光想练一练暴力...就没去想正解,谁知道正解比暴力好写不知道多少,mmp 设 f(S) 为 选集合S中的点可 ...
- HDU 4251 --- 主席树(划分树是正解)
题意:查询区间中位数 思路:模板题,相当于区间第K大的数,主席树可以水过,但划分树是正解.但还没搞明白划分树,先上模板 #include <iostream> #include <c ...
- 【百度之星2014~复赛 解题报告~正解】The Query on the Tree
声明 笔者最近意外的发现 笔者的个人网站http://tiankonguse.com/ 的很多文章被其它网站转载,但是转载时未声明文章来源或参考自 http://tiankonguse.com/ 网站 ...
- ETO的公开赛T1《矿脉开采》题解(正解)(by Zenurik)
作为T1,当然是越水越好啦qwq 显然经目测可得,那个所谓的质量评级根本就没卵用,可以直接\(W_i = W_i^{V_i}\)累积到利润里面. 这样,本问题显然是一个"子集和"问 ...
- CodeForces - 633H :Fibonacci-ish II(正解:莫对+线段树)
Yash is finally tired of computing the length of the longest Fibonacci-ish sequence. He now plays ar ...
- [luogu]P4365[九省联考]秘密袭击coat(非官方正解)
题目背景 警告:滥用本题评测者将被封号 We could have had it all. . . . . . 我们本该,拥有一切 Counting on a tree. . . . . . 何至于此 ...
- 期末考试(正解:三分单峰函数 me~)
好久没有水过杂题了! 今天lsc终于刚过了三道考试题来水杂题了! 期末考试 首先一看还是一脸mb(这是正常现象,毕竟我不像一些大神可以一眼出正解)然后我就被颓了标签,知道是三分单峰函数,但是自己实在是 ...
- PAT 甲级 1068 Find More Coins (30 分) (dp,01背包问题记录最佳选择方案)***
1068 Find More Coins (30 分) Eva loves to collect coins from all over the universe, including some ...
随机推荐
- 爬虫系列(九) xpath的基本使用
一.xpath 简介 究竟什么是 xpath 呢?简单来说,xpath 就是一种在 XML 文档中查找信息的语言 而 XML 文档就是由一系列节点构成的树,例如,下面是一份简单的 XML 文档: &l ...
- 第十五节:pandas之concat()级联
Pandas 提供了concat()函数可以轻松的将Series.DataFrame对象进行合并在一起. pandas.concat(obj , axis=0 , join="inner&q ...
- PAT 1101 Quick Sort
There is a classical process named partition in the famous quick sort algorithm. In this process we ...
- hadoop-磁盘出现坏盘,如何能在线换盘
涉及到磁盘存储路径的配置文件参数有: hdfs-site.xml <name>dfs.datanode.data.dir</name> yarn-site.xml <na ...
- ACDream - Sum
先上题目: Sum Time Limit: 6000/3000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitSta ...
- cogs 826. [Tyvj Feb11] GF打dota
826. [Tyvj Feb11] GF打dota ★★☆ 输入文件:dota.in 输出文件:dota.out 简单对比时间限制:1 s 内存限制:128 MB 众所周知,GF同学喜 ...
- android开发之使用SQLite数据库(db文件)
在开发中,有时须要使用db文件数据库.所以就须要将其导入项目,再将其使用程序写入到应用的db文件下使用. 代码非常easy.能够拿来直接使用. 要使用须要两个步骤: 1.创建raw文件.导入db文件. ...
- CodeForces 444C. DZY Loves Physics(枚举+水题)
转载请注明出处:http://blog.csdn.net/u012860063/article/details/37509207 题目链接:http://codeforces.com/contest/ ...
- mysql中 show table status 获取表信息
用法 mysql>show table status; mysql>show table status like 'esf_seller_history'\G; mysql>show ...
- thymeleaf+springboot找不到html,只返回了字符串
在浏览器用链接http://localhost:8080/city/page/list 访问时页面上只出现了cityList字样,预期是返回cityList.html 解决:在controller中使 ...