Bring Them There

Time Limit: 3000ms
Memory Limit: 131072KB

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 (2N50, 1M200, 1K50, 1STNS  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 ABmeans 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

  1. 6 7 4 1 6
  2. 1 2
  3. 2 3
  4. 3 5
  5. 5 6
  6. 1 4
  7. 4 6
  8. 4 3

Sample Output

  1. 4
  2. 2 1 2 2 4
  3. 3 1 3 2 6 3 4
  4. 3 1 5 3 6 4 4
  5. 2 1 6 4 6

Source

 
解题:大白上面的题目,网络流拆点,有些难度,坑爹的地方在于使用dinic算法,不能继续多路增广了,一旦达到那个阈值,必须停止增广,否则,WA
输出确实巧妙狗血
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int INF = ~0U>>;
  4. const int maxn = ;
  5. struct arc {
  6. int to,flow,next;
  7. arc(int x = ,int y = ,int z = -) {
  8. to = x;
  9. flow = y;
  10. next = z;
  11. }
  12. } e[maxn*];
  13. int head[maxn],d[maxn],cur[maxn],tot,S,T;
  14. void add(int u,int v,int flow) {
  15. e[tot] = arc(v,flow,head[u]);
  16. head[u] = tot++;
  17. e[tot] = arc(u,,head[v]);
  18. head[v] = tot++;
  19. }
  20. bool bfs() {
  21. queue<int>q;
  22. memset(d,-,sizeof d);
  23. q.push(S);
  24. d[S] = ;
  25. while(!q.empty()) {
  26. int u = q.front();
  27. q.pop();
  28. for(int i = head[u]; ~i; i = e[i].next) {
  29. if(e[i].flow && d[e[i].to] == -) {
  30. d[e[i].to] = d[u] + ;
  31. q.push(e[i].to);
  32. }
  33. }
  34. }
  35. return d[T] > -;
  36. }
  37. int dfs(int u,int low) {
  38. if(u == T) return low;
  39. int a,tmp = ;
  40. for(int &i = cur[u]; ~i; i = e[i].next) {
  41. if(e[i].flow &&d[e[i].to] == d[u]+&&(a=dfs(e[i].to,min(low,e[i].flow)))) {
  42. e[i].flow -= a;
  43. e[i^].flow += a;
  44. low -= a;
  45. tmp += a;
  46. break;
  47. }
  48. }
  49. if(!tmp) d[u] = -;
  50. return tmp;
  51. }
  52. int dinic(int bound,int ret = ) {
  53. while(ret < bound && bfs()) {
  54. memcpy(cur,head,sizeof head);
  55. ret += dfs(S,INF);
  56. }
  57. return ret;
  58. }
  59. int n,m,k,s,t;
  60. int x[maxn],y[maxn];
  61. void output(int day) {
  62. int to[],vis[],s[],t[];
  63. for(int i = ; i <= k; ++i) to[i] = S;
  64. int id = ;
  65. for(int d = ; d <= day; ++d) {
  66. id += (n<<); //跳过计算机停留在某个星球上一天的边
  67. int cnt = ;
  68. for(int i = ; i < m; ++i) {
  69. int flow1 = e[id].flow;
  70. id += ;
  71. int flow2 = e[id].flow;
  72. id += ;
  73. if(flow1 && !flow2) s[cnt] = y[i], t[cnt++] = x[i];
  74. if(flow2 && !flow1) s[cnt] = x[i], t[cnt++] = y[i];
  75. }
  76. memset(vis,,sizeof vis);
  77. printf("%d", cnt);
  78. for(int i = ; i < cnt; ++i)
  79. for(int j = ; j <= k; ++j)
  80. if(s[i] == to[j] && !vis[j]) {
  81. printf(" %d %d", j, t[i]);
  82. to[j] = t[i];
  83. vis[j] = ;
  84. break;
  85. }
  86. printf("\n");
  87. }
  88. }
  89. void solve() {
  90. int ret = ,day = ;
  91. while(ret < k) {
  92. ++day;
  93. for(int i = ; i <= n; ++i)
  94. add((day - )*n + i,day*n + i,INF);
  95. for(int i = ; i < m; ++i) {
  96. add(x[i] + (day - )*n,y[i] + day*n,);
  97. add(y[i] + (day - )*n,x[i] + day*n,);
  98. }
  99. S = s;
  100. T = t + day*n;
  101. ret += dinic(k - ret);
  102. }
  103. printf("%d\n",day);
  104. output(day);
  105. }
  106. int main() {
  107. while(~scanf("%d%d%d%d%d",&n,&m,&k,&s,&t)) {
  108. memset(head,-,sizeof head);
  109. for(int i = tot = ; i < m; ++i)
  110. scanf("%d%d",x + i,y + i);
  111. solve();
  112. }
  113. return ;
  114. }

UVALive 2957 Bring Them There的更多相关文章

  1. 【清华集训】楼房重建 BZOJ 2957

    Description 小A的楼房外有一大片施工工地,工地上有N栋待建的楼房.每天,这片工地上的房子拆了又建.建了又拆.他经常无聊地看着窗外发呆,数自己能够看到多少栋房子. 为了简化问题,我们考虑这些 ...

  2. UVALive - 4108 SKYLINE[线段树]

    UVALive - 4108 SKYLINE Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug ...

  3. UVALive - 3942 Remember the Word[树状数组]

    UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...

  4. UVALive - 3942 Remember the Word[Trie DP]

    UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...

  5. HYSBZ 2957 分块

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2957 题意:中文题面 思路: 来自此博客 首先明确问题,对于每栋楼房的斜率K=H/X,问题 ...

  6. [BZOJ 2957]楼房重建(THU2013集训)(分块思想)

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2957 分析: 首先明确问题,对于每栋楼房的斜率K=H/X,问题就是问有多少个楼房的K比前面所有 ...

  7. 思维 UVALive 3708 Graveyard

    题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...

  8. 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 ...

  9. UVALive 6145 Version Controlled IDE(可持久化treap、rope)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

随机推荐

  1. JAVA线程操作常见面试题 包括不使用内部类对多个线程加减1

    class ManyThreads2 { private int j = 0; public synchronized void inc() { j++; System.out.println(Thr ...

  2. eclipse 当安装jad仍然不能反编译,提示attach source的时候

    当安装jad仍然不能反编译,提示attach source的时候,其实是当前workspace有问题了: 所使用的workspace目录下.metadata\.mylyn会出现一个.tasks.xml ...

  3. Suricata的配置

    见官网 https://suricata.readthedocs.io/en/latest/configuration/index.html# Docs » 8. Configuration Edit ...

  4. Android利用融云做异地登录提醒

    在RongCloudEvent下找到onChanged方法 @Override public void onChanged(ConnectionStatus connectionStatus) { s ...

  5. Ubuntu16.04常用操作命令总结ing

    查看软件安装目录:whereis 软件名称(如:whereis mysql,where is sqlite3等) 安装软件:apt/apt-get install 软件名称(如:apt/apt-get ...

  6. 洛谷P1724 东风谷早苗

    题目描述 在幻想乡,东风谷早苗是以高达控闻名的高中生宅巫女.某一天,早苗终于入手了最新款的钢达姆模型.作为最新的钢达姆,当然有了与以往不同的功能了,那就是它能够自动行走,厉害吧(好吧,我自重).早苗的 ...

  7. PHP环境搭建Zend Studio 10.6.2+WampServer2.4

    址:http://www.zend.com/en/products/studio/downloads直接下载地址:http://downloads.zend.com/studio-eclipse/10 ...

  8. Git 版本控制系统的基本使用、常用操作

    以Ubuntu16.04操作系统为例(其他系统类似),主要记录常用的.基本操作: 0. 安装Git 分散型版本控制系统(CVS): sudo apt-get install git 1. 初始化本地配 ...

  9. GitHub简单命令行# 使用命令行传代码到GitHub

    第一次提交代码到Github 第一步: 建立本地仓库cd到你的本地项目根目录下,执行git命令 cd到本地项目 git init 第二步: 将本地项目工作区的所有文件添加到暂存区 git add . ...

  10. MySQL-07 日志管理

    学习目标 MySQL日志 二进制日志 错误日志 查询通用日志 慢查询日志 MySQL日志 MySQL日志分为四类,说明如下: 错误日志:记录MySQL服务的启动.运行或者停止时出现的问题. 查询日志: ...