TZOJ 3711 浪漫自习(最大流)
描述
如今的校园谈恋爱已是习以为常,这不,去上自习也要成双成对的。现在假设某班里有N对情侣从同一寝室楼出发,到达同一个教室上自习。途中,她们可能会经过长廊、静溪等一系列的景点观光游览。但情侣们不希望在途中碰到班里的其他情侣而扫了雅兴。现在给定包括寝室、教室、以及各个景点在内共有M个场景,以及这些场景之间的路径分布情况,请您帮忙为情侣们设计各自单独的散步路线。

输入
输入数据有多组,每组数据的第一行为2个正整数N(1<=N<=50)和M(2<=M<=50),分别表示共有N对情侣,M个场景,我们对场景从1~M进行编号。接下来的M行中,其中第i行的第一个数为正整数K,后面有K个正整数,表示与第i个场景之间有路径相连的场景编号。场景之间的路径是双向的,因此如果a与b之间有路径,那么b与a之间也必然有路径。我们始终假设:编号为1的场景是出发地——寝室楼,编号为2的场景是情侣们的目的地——自习教室。
当N和M均为0时输入结束。
输出
如果能够为情侣们设计出各自单独的散步路线(即除了出发地和目的地外,之间永远不会碰面),那么请输出YES,否则输出NO。
样例输入
3 5
3 3 4 5
3 3 4 5
2 1 2
2 1 2
2 1 2
4 5
3 3 4 5
3 3 4 5
2 1 2
2 1 2
2 1 2
0 0
样例输出
YES
NO
提示
样例的第一个实例对应的解决方案是:
1->3->2
1->4->2
1->5->2

题意
为N对情侣设置各自的路线(从1到2),要求路线不重叠,求是否能满足N对情侣
题解
每条边流量为1,源点S=1,汇点T=2,跑一遍最大流
代码
#include<bits/stdc++.h>
using namespace std; const int N=,M=;
int c[N][N],pre[N],n,m;
bool bfs()
{
int vis[N]={};
memset(pre,,sizeof pre);
queue<int>q;
q.push();
while(!q.empty())
{
int u=q.front();q.pop();
for(int v=;v<=m;v++)
{
if(c[u][v]>&&!vis[v])
{
pre[v]=u;
if(v==)return true;
vis[v]=;
q.push(v);
}
}
}
return false;
}
int maxflow()
{
int flow=;
while(bfs())
{
int d=1e9;
for(int i=;i!=;i=pre[i])d=min(d,c[pre[i]][i]);
for(int i=;i!=;i=pre[i])
c[pre[i]][i]-=d,
c[i][pre[i]]+=d;
flow+=d;
}
return flow;
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF,n||m)
{
memset(c,,sizeof c);
for(int i=,k;i<=m;i++)
{
scanf("%d",&k);
for(int j=,v;j<=k;j++)
{
scanf("%d",&v);
c[i][v]=c[v][i]=;
}
}
printf("%s\n",maxflow()>=n?"YES":"NO");
}
return ;
}
TZOJ 3711 浪漫自习(最大流)的更多相关文章
- TZOJ 4085 Drainage Ditches(最大流)
描述 Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. Th ...
- TZOJ 4712 Double Shortest Paths(最小费用最大流)
描述 Alice and Bob are walking in an ancient maze with a lot of caves and one-way passages connecting ...
- TZOJ 1911 A Plug for UNIX(最大流)
描述 You are in charge of setting up the press room for the inaugural meeting of the United Nations In ...
- TZOJ 1705 Dining(拆点最大流)
描述 Cows are such finicky eaters. Each cow has a preference for certain foods and drinks, and she wil ...
- TZOJ 1513 Farm Tour(最小费用最大流)
描述 When FJ's friends visit him on the farm, he likes to show them around. His farm comprises N (1 &l ...
- TZOJ 1594 Optimal Milking(二分+最大流)
描述 FJ has moved his K (1 <= K <= 30) milking machines out into the cow pastures among the C (1 ...
- 微信小程序实战,用vue3实现每日浪漫情话推荐~
之前做了个恋爱话术微信小程序,实现高情商的恋爱聊天. 但最近突然发现,每天早上给女朋友发一段优美情话可以让她开心一整天,但无奈自己的语言水平确实有限,不能随手拈来,着实让人有点不爽. 不过办法总比困难 ...
- 使用C#处理基于比特流的数据
使用C#处理基于比特流的数据 0x00 起因 最近需要处理一些基于比特流的数据,计算机处理数据一般都是以byte(8bit)为单位的,使用BinaryReader读取的数据也是如此,即使读取bool型 ...
- HTML 事件(三) 事件流与事件委托
本篇主要介绍HTML DOM中的事件流和事件委托. 其他事件文章 1. HTML 事件(一) 事件的介绍 2. HTML 事件(二) 事件的注册与注销 3. HTML 事件(三) 事件流与事件委托 4 ...
随机推荐
- 【JEECG技术文档】JEECG 接口权限开发及配置使用说明
1.功能介绍 通过接口配置实现,对接口的访问权限控制和数据权限控制,接口时REST接口,接口权限认证机制使用Json web token (JWT) 接口权限调用流程: (1)通过接口用户的用户名 ...
- C++11并发之std::thread<转>
最近技术上没什么大的收获,也是悲催的路过~ 搞一点新东西压压惊吧! C++11并发之std::thread 知识链接: C++11 并发之std::mutex C++11 并发之std::atomic ...
- 区分slice,splice和split方法
1.slice(数组) 用法:array.slice(start,end) 解释:该方法是对数组进行部分截取,并返回一个数组副本:参数start是截取的开始数组索引,end参数等于你要取的最后一个字符 ...
- hadoop-3
结合https://blog.csdn.net/zhangjun5965/article/details/76796998,自己过一遍感受下 public class DFSZKFailoverCon ...
- byobu copy
Copy and Paste in Scrollback mode (screen/byobu) Enter scrollback mode: F7 Move the cursor to the st ...
- php装curl拓展出错
错误: checking for cURL in default path... not found checking for cURL 7.10.5 or greater... ./configur ...
- sql中优化查询
1.在大部分情况下,where条件语句中包含or.not,SQL将不使用索引:可以用in代替or,用比较运算符!=代替not. 2.在没有必要显示不重复运行时,不使用distinct关键字,避免增加处 ...
- 【386】operator 的 itemgetter、slice、and_、or_
itemgetter 用来获取数组中指定索引的元素 from operator import itemgetter itemgetter(1, 3, 5)('ABCDEFG') output: ('B ...
- node-sass:npm install node-sass --save
从git上拉下来的项目,要先安装依赖, 再运行. 缺少node-sass:npm install node-sass --save
- windows安装xgboost
https://blog.csdn.net/leo_xu06/article/details/52300869 参考部分共同安装的部分: https://www.cnblogs.com/kongcon ...