UVALive 2957 Bring Them There
Bring Them There
This problem will be judged on UVALive. Original ID: 2957
64-bit integer IO format: %lld Java class name: Main
By the year 3141, the human civilization has spread all over the galaxy. The special hypertunnels are used to travel from one star system to another. To use the hypertunnel, you fly to a special location near the source star using your spaceship, activate the hyperjumper, fly through the hypertunnel, get out near your destination star and fly to the planet you need. The whole process takes exactly one day. A small drawback of the system is that for each tunnel every day only one spaceship can travel using this tunnel.
You are working in the transportation department of the ``Intergalaxy Business Machines" company. This morning your boss has assigned a new task to you. To run the programming contest IBM needs to deliver K supercomputers from Earth where the company headquarters are located to the planet Eisiem. Since supercomputers are very large, one needs the whole spaceship to carry each supercomputer. You are asked to find a plan to deliver the supercomputers that takes as few days as possible. Since IBM is a very powerful corporation, you may assume that any time you need some tunnel for hyperjump, it is at your service. However, you still can use each tunnel only once a day.
Input
Input consists of several datasets. The first line of each dataset contains N - the number of star systems in the galaxy, M - the number of tunnels, K - the number of supercomputers to be delivered, S - the number of the solar system (the system where planet Earth is) and T - the number of the star system where planet Eisiem is (2
N
50, 1
M
200, 1
K
50, 1
S, T
N, S
T).
Next M lines contain two different integer numbers each and describe tunnels. For each tunnel the numbers of star systems that it connects are given. The tunnel can be traveled in both directions, but remember that each day only one ship can travel through it, in particular, two ships cannot simultaneously travel through the same tunnel in opposite directions. No tunnel connects a star to itself and any two stars are connected by at most one tunnel.
Output
On the first line of the output for each dataset print L - the fewest number of days needed to deliver K supercomputers from star system S to star system T using hypertunnels. Next Llines must describe the process. Each line must start with Ci - the number of ships that travel from one system to another this day. Ci pairs of integer numbers must follow, pair A, Bmeans that the ship number A travels from its current star system to star system B.
It is guaranteed that there is a way to travel from star system S to star system T.
Sample Input
6 7 4 1 6
1 2
2 3
3 5
5 6
1 4
4 6
4 3
Sample Output
4
2 1 2 2 4
3 1 3 2 6 3 4
3 1 5 3 6 4 4
2 1 6 4 6
Source
#include <bits/stdc++.h>
using namespace std;
const int INF = ~0U>>;
const int maxn = ;
struct arc {
int to,flow,next;
arc(int x = ,int y = ,int z = -) {
to = x;
flow = y;
next = z;
}
} e[maxn*];
int head[maxn],d[maxn],cur[maxn],tot,S,T;
void add(int u,int v,int flow) {
e[tot] = arc(v,flow,head[u]);
head[u] = tot++;
e[tot] = arc(u,,head[v]);
head[v] = tot++;
}
bool bfs() {
queue<int>q;
memset(d,-,sizeof d);
q.push(S);
d[S] = ;
while(!q.empty()) {
int u = q.front();
q.pop();
for(int i = head[u]; ~i; i = e[i].next) {
if(e[i].flow && d[e[i].to] == -) {
d[e[i].to] = d[u] + ;
q.push(e[i].to);
}
}
}
return d[T] > -;
}
int dfs(int u,int low) {
if(u == T) return low;
int a,tmp = ;
for(int &i = cur[u]; ~i; i = e[i].next) {
if(e[i].flow &&d[e[i].to] == d[u]+&&(a=dfs(e[i].to,min(low,e[i].flow)))) {
e[i].flow -= a;
e[i^].flow += a;
low -= a;
tmp += a;
break;
}
}
if(!tmp) d[u] = -;
return tmp;
}
int dinic(int bound,int ret = ) {
while(ret < bound && bfs()) {
memcpy(cur,head,sizeof head);
ret += dfs(S,INF);
}
return ret;
}
int n,m,k,s,t;
int x[maxn],y[maxn];
void output(int day) {
int to[],vis[],s[],t[];
for(int i = ; i <= k; ++i) to[i] = S;
int id = ;
for(int d = ; d <= day; ++d) {
id += (n<<); //跳过计算机停留在某个星球上一天的边
int cnt = ;
for(int i = ; i < m; ++i) {
int flow1 = e[id].flow;
id += ;
int flow2 = e[id].flow;
id += ;
if(flow1 && !flow2) s[cnt] = y[i], t[cnt++] = x[i];
if(flow2 && !flow1) s[cnt] = x[i], t[cnt++] = y[i];
}
memset(vis,,sizeof vis);
printf("%d", cnt);
for(int i = ; i < cnt; ++i)
for(int j = ; j <= k; ++j)
if(s[i] == to[j] && !vis[j]) {
printf(" %d %d", j, t[i]);
to[j] = t[i];
vis[j] = ;
break;
}
printf("\n");
}
}
void solve() {
int ret = ,day = ;
while(ret < k) {
++day;
for(int i = ; i <= n; ++i)
add((day - )*n + i,day*n + i,INF);
for(int i = ; i < m; ++i) {
add(x[i] + (day - )*n,y[i] + day*n,);
add(y[i] + (day - )*n,x[i] + day*n,);
}
S = s;
T = t + day*n;
ret += dinic(k - ret);
}
printf("%d\n",day);
output(day);
}
int main() {
while(~scanf("%d%d%d%d%d",&n,&m,&k,&s,&t)) {
memset(head,-,sizeof head);
for(int i = tot = ; i < m; ++i)
scanf("%d%d",x + i,y + i);
solve();
}
return ;
}
UVALive 2957 Bring Them There的更多相关文章
- 【清华集训】楼房重建 BZOJ 2957
Description 小A的楼房外有一大片施工工地,工地上有N栋待建的楼房.每天,这片工地上的房子拆了又建.建了又拆.他经常无聊地看着窗外发呆,数自己能够看到多少栋房子. 为了简化问题,我们考虑这些 ...
- UVALive - 4108 SKYLINE[线段树]
UVALive - 4108 SKYLINE Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug ...
- UVALive - 3942 Remember the Word[树状数组]
UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...
- UVALive - 3942 Remember the Word[Trie DP]
UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...
- HYSBZ 2957 分块
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2957 题意:中文题面 思路: 来自此博客 首先明确问题,对于每栋楼房的斜率K=H/X,问题 ...
- [BZOJ 2957]楼房重建(THU2013集训)(分块思想)
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2957 分析: 首先明确问题,对于每栋楼房的斜率K=H/X,问题就是问有多少个楼房的K比前面所有 ...
- 思维 UVALive 3708 Graveyard
题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...
- he time that it takes to bring a block from disk into main memory
DATABASE SYSTEM CONCEPTS, SIXTH EDITION There is a trade-off that the system designer must make betw ...
- UVALive 6145 Version Controlled IDE(可持久化treap、rope)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
随机推荐
- vmware虚拟机启动centOs黑屏
如图所示 , 我的VM 启动虚拟机之后就变成了上面的样子,一直不动,ping也ping不好,这个时候 : 1. 要么 内存不够了: 2. 要么 网络协议存在问题了: 本地windows环境在管理员的 ...
- Suricata的规则解读(默认和自定义)
不多说,直接上干货! 见suricata官网 https://suricata.readthedocs.io/en/latest/rules/index.html 一.Suricata的规则所放位置 ...
- 搭建一个高可用的redis环境
一.环境准备 我的环境: Fedora 25 server 64位版 6台: 192.168.10.204 192.168.10.205 192.168.10.206 192.168.10.203 ...
- angularjs 下select中ng-options使用
当我有一堆object数据要用下拉框进行显示选择时,可以使用到angularjs中的select中的ng-options的属性.官网网址:https://docs.angularjs.org/api/ ...
- 分层开发之C#分层
假如没有用分层开发,仔细分析三人的开发过程,很容易发现其中的问题: >三人排队式的轮番工作,花费的时间是三人工作时间之和. >后面开发的人基本都是要先花费时间熟悉前面人的代码,否则开发难以 ...
- ssl证书过期问题解决
1,ssl证书失效现象 小程序debug有如下证书无效信息: 浏览器访问https://ic-park.net:30001/indoornav/callFunction1.php 提示证书风险. 2, ...
- JavaScript也谈内存优化
相对C/C++ 而言,我们所用的JavaScript 在内存这一方面的处理已经让我们在开发中更注重业务逻辑的编写.但是随着业务的不断复杂化,单页面应用.移动HTML5 应用和Node.js 程序等等的 ...
- Hadoop 安装过程中出现的问题
1.hadoop-daemon.sh start namenode 启动失败 查看hadoop/logs 下面的日志 出现 2017-04-11 15:35:13,860 WARN org.apach ...
- Zotero文献管理神器使用
为什么使用Zotero管理论文? 1.可以从网上剪藏 2.可以查询 3.有作者 标题 期刊 索引 4.word自动生成论文索引 把pdf文件导入Zotero 按住ctrl+shift拖动pdf文件,就 ...
- 阿里云服务器ECS部署应用教程
购买阿里云服务器 大多数云服务器默认安装的语言运行环境版本都很旧了,python用的还是2.7,JDK用的还是1.6的,在ECS云服务器中可以自行安装,包括python3.4之类的. 在次页面购买EC ...