Crowd Control
我的图论还是只会套模板 嘤嘤嘤
题目描述
The BAPC draws a large number of visitors to Amsterdam. Many of these people arrive at the train station, then walk from intersection to intersection through the streets of Amsterdam in a big parade until they reach the BAPC location.
A street can only allow a certain number of people per hour to pass through. This is called the capacity of the street. The number of people going through a street must never exceed its capacity, otherwise accidents will happen. People may walk through a street in either direction.
The BAPC organizers want to prepare a single path from train station to BAPC location. They choose the path with maximum capacity, where the capacity of a path is defined to be the minimum capacity of any street on the path. To make sure that nobody walks the wrong way, the organizers close down the streets which are incident
1 to an intersection on the path,but not part of the path.
Can you write a program to help the organizers decide which streets to block? Given a graph of the streets and intersections of Amsterdam, produce the list of streets that need to be closed down in order to create a single maximum-capacity path from the train station to the BAPC. The path must be simple, i.e. it may not visit any intersection more than once.
输入
• The first line contains two integers: n, the number of intersections in the city, and m,the number of streets (1 ≤ n, m ≤ 1000).
• The following m lines each specify a single street. A street is specified by three integers, ai, bi and ci, where ai and bi are ids of the two intersections that are connected by this street (0 ≤ ai, bi < n) and ci is the capacity of this street (1 ≤ ci ≤ 500000). Streets are numbered from 0 to m − 1 in the given order.
You may assume the following:
• All visitors start walking at the train station which is the intersection with id 0. The BAPC is located at the intersection with id n − 1.
• The intersections and streets form a connected graph.
• No two streets connect the same pair of intersections.
• No street leads back to the same intersection on both ends.
• There is a unique simple path of maximum capacity.
输出
Output a single line containing a list of space separated street numbers that need to be blocked in order to create a single maximum-capacity path from train station to BAPC. Sort these street numbers in increasing order.
If no street must be blocked, output the word “none” instead.
样例输入
7 10
0 1 800
1 2 300
2 3 75
3 4 80
4 5 50
4 6 100
6 1 35
0 6 10
0 2 120
0 3 100
样例输出
0 2 4 6 7 8
审题!不要看到流量就差点把网络流模板套上去了!
首先思考怎样才能使流量最大呢?就要让这条路上最小的边最大,然后就想到最大生成树。
审题!为什么1 2不用封,因为他不想让人走岔路,所以正确道路上的所有岔路都要封住,其他不用管。找到正确道路了怎么办?用一个bfs标记每个点的父亲,然后再用dfs从汇点开始向上找源点,于是就找到了这条道路的点。然后再判断边是否与该点相连。
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int maxn=1010;
int N,M;
int fa[maxn];
int dist[maxn][maxn];
struct edge
{
int u,v,w,id;
edge(int u=0,int v=0,int w=0):u(u),v(v),w(w){}
}e[maxn];
int getfather(int x)
{
if(x==fa[x]) return x;
else return fa[x]=getfather(fa[x]);
}
bool cmp(edge x,edge y)
{
return x.w>y.w;
}
void kruscal()
{
sort(e,e+M,cmp);
int cnt=0;
for(int i=0;i<N;i++){
fa[i]=i;
}
for(int i=0;i<M;i++){
int t1=getfather(e[i].u);
int t2=getfather(e[i].v);
if(t1!=t2){
fa[t1]=t2;
dist[e[i].u][e[i].v]=dist[e[i].v][e[i].u]=e[i].w;
cnt++;
}
if(cnt==N-1) break;
}
return ;
}
bool vis[maxn];
int d[maxn];
int ans[maxn][maxn];
bool selct[maxn];
bool del[maxn];
queue<int>q;
void bfs(int u)
{
q.push(u);
vis[u]=true;
while(!q.empty()){
u=q.front();
q.pop();
for(int i=0;i<N;i++){
if(!vis[i]&&dist[u][i]>0){
d[i]=u;
vis[i]=true;
q.push(i);
}
}
}
}
void dfs(int u){
int v=d[u];
del[u]=1;
if(v==0){
ans[0][u]=1;
ans[u][0]=1;
del[0]=1;
return;
}
else{
ans[v][u]=1;
ans[u][v]=1;
dfs(v);
}
return;
}
int main()
{
int u,v,w;
//freopen("in.txt","r",stdin);
scanf("%d%d",&N,&M);
for(int i=0;i<M;i++){
scanf("%d%d%d",&u,&v,&w);
edge k(u,v,w);
k.id=i;
e[i]=k;
}
kruscal();
bfs(0);
dfs(N-1);
bool flag=0;
//for(int i=0;i<N;i++) cout<<del[i]<<" ";
//cout<<endl;
for(int i=0;i<M;i++){
if(del[e[i].u]||del[e[i].v])
if(ans[e[i].u][e[i].v]==0){
selct[e[i].id]=true;
flag=1;
}
}
if(flag)
for(int i=0;i<M;i++){
if(selct[i]){
printf("%d ",i);
}
}
else{
printf("none");
}
printf("\n");
//fclose(stdin);
return 0;
}
Crowd Control的更多相关文章
- Crowd Control(输出不在最大值最小化的最短路上的边)
题意: 就是求完最大值最小化 然后输出在这条最大值最小化的最短路上的点的不在最短路上的边,emm.... 解析: 很明显,先套spfa最大值最小化模板,emm... 在更新d的时候 用一个pre去记 ...
- BAPC2017
Benelux Algorithm Programming Contest 2017 参考资料: https://blog.csdn.net/sizaif/article/details/798586 ...
- Atlassian 系列软件安装(Crowd+JIRA+Confluence+Bitbucket+Bamboo)
公司使用的软件开发和协作工具为 Atlassian 系列软件,近期需要从腾讯云迁移到阿里云环境,简单记录下安装和配置过程.(Atlassian 的文档非常详尽,过程中碰见的问题都可以找到解决办法.) ...
- 企业管理软件开发架构之七 Object Control设计与运用
在做查询时,经常遇到一类需求.请看下面的SQL语句查询 SELECT * FROM Company WHERE CompanyCode='Kingston' AND Suspended='N' AND ...
- 文字处理控件TX Text Control的使用
这几天一直在研究TX Text Control的使用,由于这方面的资料相对比较少,主要靠下载版本的案例代码进行研究,以及官方的一些博客案例进行学习,使用总结了一些心得,特将其总结出来,供大家分享学习. ...
- Sublime text 2/3 中 Package Control 的安装与使用方法
Package Control 插件是一个方便 Sublime text 管理插件的插件,但因为 Sublime Text 3 更新了 Python 的函数,API不同了,导致基于 Python 开发 ...
- Java 性能分析工具 , 第 3 部分: Java Mission Control
引言 本文为 Java 性能分析工具系列文章第三篇,这里将介绍如何使用 Java 任务控制器 Java Mission Control 深入分析 Java 应用程序的性能,为程序开发人员在使用 Jav ...
- Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details
thinkphp 在Apache上配置启用伪静态,重启Apache1 restart 竟然失败了,报错 Job for httpd.service failed because the control ...
- Neural Pathways of Interaction Mediating the Central Control of Autonomic Bodily State 自主神经系统-大脑调节神经通路
Figure above: Critchley H D, Harrison N A. Visceral influences on brain and behavior[J]. Neuron, 201 ...
随机推荐
- 第二阶段scrum-2
1.整个团队的任务量: 2.任务看板: 会议照片: 产品状态: 正在连接配置数据库部分
- IDEA的一些常用设置
一.给方法之间添加分割线 效果: 二.自动导包 三.字体以及大小和行间距 四.注释的字体颜色 五.项目编码 六.省点模式(开启省点模式后会取消代码检查和提示等,需要注意) 七.代码垂直或者水平分区显示 ...
- (递归)P1192 台阶问题
题解: 这其实是变相的斐波那契,观察下列等式: //k=2 : 1 2 3 5 8 13 21 34...... //k=3 : 1 2 4 7 13 24 44 81... //k=4 : 1 2 ...
- 寒假day19
今天编写了人才动态模块,同时刷了一些算法题.
- JSP三大指令(Page指令,include指令,taglib指令)
参考文章: https://www.runoob.com/jsp/jsp-directives.html http://c.biancheng.net/view/1458.html https://b ...
- 程序员用 Python 扒出 B 站那些“惊为天人”的UP主!
前言 ! 近期B站的跨年晚会因其独特的创意席卷各大视频网站,给公司带来了极大的正面影响,股价也同时大涨,想必大家都在后悔没有早点买B站的股票: 然而今天我们要讨论的不是B站的跨年晚会,而是B站 ...
- OSS 图片处理流程
1.步骤一 2.步骤二 3.步骤三 4.步骤四 5.步骤五(步骤4完成会自动添加cname用户解析,不需要自己去加,只需要点击进来看下是否添加成功即可) 通过以上步骤就可以实现了图片服务的配置
- Unity3D一些基本的概念和一些基本操作
场景:整个游戏由场景组成,一个游戏至少要有一个场景,如果把所有的游戏画面放在一个场景里也是可以的,如果游戏非常非常的大,如果所有的东西都放到一个场景里那么结构就不是那么清晰了而且处理起来就会麻烦一些, ...
- Linux-socket编程接口介绍
1.建立连接 (1).socket.socket函数类似于open,用来打开一个网络连接,如果打开成功则返回一个网络文件描述符(int类型),之后我们操作这个网络连接都可以通过这个网络文件描述符. ( ...
- http head详解
Http普通报头: 少数报头域用于所有的请求和响应消息, 但并不用于被传输的实体 cache-Control: 用于指定缓存指令, 缓存指令是单向的 ,且是独立的(一个消息的缓存指令不会影 ...