Island Transport

Time Limit: 10000ms
Memory Limit: 65536KB

This problem will be judged on HDU. Original ID: 4280
64-bit integer IO format: %I64d      Java class name: Main

In the vast waters far far away, there are many islands. People are living on the islands, and all the transport among the islands relies on the ships.
  You have a
transportation company there. Some routes are opened for passengers.
Each route is a straight line connecting two different islands, and it
is bidirectional. Within an hour, a route can transport a certain number
of passengers in one direction. For safety, no two routes are cross or
overlap and no routes will pass an island except the departing island
and the arriving island. Each island can be treated as a point on the XY
plane coordinate system. X coordinate increase from west to east, and Y
coordinate increase from south to north.
  The transport capacity is
important to you. Suppose many passengers depart from the westernmost
island and would like to arrive at the easternmost island, the maximum
number of passengers arrive at the latter within every hour is the
transport capacity. Please calculate it.

Input

  The first line contains one integer T (1<=T<=20), the number of test cases.
 
 Then T test cases follow. The first line of each test case contains two
integers N and M (2<=N,M<=100000), the number of islands and the
number of routes. Islands are number from 1 to N.
  Then N lines
follow. Each line contain two integers, the X and Y coordinate of an
island. The K-th line in the N lines describes the island K. The
absolute values of all the coordinates are no more than 100000.
  
Then M lines follow. Each line contains three integers I1, I2
(1<=I1,I2<=N) and C (1<=C<=10000) . It means there is a
route connecting island I1 and island I2, and it can transport C
passengers in one direction within an hour.
  It is guaranteed that
the routes obey the rules described above. There is only one island is
westernmost and only one island is easternmost. No two islands would
have the same coordinates. Each island can go to any other island by the
routes.

 

Output

  For each test case, output an integer in one line, the transport capacity.

 

Sample Input

2
5 7
3 3
3 0
3 1
0 0
4 5
1 3 3
2 3 4
2 4 3
1 5 6
4 5 3
1 4 4
3 4 2
6 7
-1 -1
0 1
0 2
1 0
1 1
2 3
1 2 1
2 3 6
4 5 5
5 6 3
1 4 6
2 5 5
3 6 4

Sample Output

9
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[];
int head[maxn],d[maxn],gap[maxn],tot,S,T,n,m;
void add(int u,int v,int flow){
e[tot] = arc(v,flow,head[u]);
head[u] = tot++;
e[tot] = arc(u,flow,head[v]);
head[v] = tot++;
}
queue<int>q;
void bfs(){
for(int i = ; i <= n; ++i){
d[i] = -;
gap[i] = ;
}
d[T] = ;
q.push(T);
while(!q.empty()){
int u = q.front();
q.pop();
++gap[d[u]];
for(int i = head[u]; ~i; i = e[i].next){
if(d[e[i].to] == -){
d[e[i].to] = d[u] + ;
q.push(e[i].to);
}
}
}
}
int dfs(int u,int low){
if(u == T) return low;
int tmp = ,minH = n - ;
for(int i = head[u]; ~i; i = e[i].next){
if(e[i].flow){
if(d[e[i].to] + == d[u]){
int a = dfs(e[i].to,min(low,e[i].flow));
e[i].flow -= a;
e[i^].flow += a;
low -= a;
tmp += a;
if(!low) break;
if(d[S] >= n) return tmp;
}
if(e[i].flow) minH = min(minH,d[e[i].to]);
}
}
if(!tmp){
if(--gap[d[u]] == ) d[S] = n;
++gap[d[u] = minH + ];
}
return tmp;
}
int main(){
int kase,x,y,s,t,u,v,w;
scanf("%d",&kase);
while(kase--){
scanf("%d%d",&n,&m);
memset(head,-,sizeof head);
s = INF;
int ret = t = ;
for(int i = ; i <= n; ++i){
scanf("%d%d",&x,&y);
if(s > x){
s = x;
S = i;
}
if(t < x){
t = x;
T = i;
}
}
for(int i = tot = ; i < m; ++i){
scanf("%d%d%d",&u,&v,&w);
add(u,v,w);
}
bfs();
while(d[S] < n) ret += dfs(S,INF);
printf("%d\n",ret);
}
return ;
}

HDU 4280 Island Transport的更多相关文章

  1. HDU 4280 Island Transport(网络流,最大流)

    HDU 4280 Island Transport(网络流,最大流) Description In the vast waters far far away, there are many islan ...

  2. Hdu 4280 Island Transport(最大流)

    Island Transport Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  3. HDU 4280 Island Transport(无向图最大流)

    HDU 4280:http://acm.hdu.edu.cn/showproblem.php?pid=4280 题意: 比较裸的最大流题目,就是这是个无向图,并且比较卡时间. 思路: 是这样的,由于是 ...

  4. HDU 4280 Island Transport(dinic+当前弧优化)

    Island Transport Description In the vast waters far far away, there are many islands. People are liv ...

  5. HDU 4280 Island Transport(网络流)

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:pid=4280">http://acm.hdu.edu.cn/showproblem.php ...

  6. HDU 4280 Island Transport(HLPP板子)题解

    题意: 求最大流 思路: \(1e5\)条边,偷了一个超长的\(HLPP\)板子.复杂度\(n^2 \sqrt{m}\).但通常在随机情况下并没有isap快. 板子: template<clas ...

  7. 【HDUOJ】4280 Island Transport

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4280 题意:有n个岛屿,m条无向路,每个路给出最大允许的客流量,求从最西的那个岛屿最多能运用多少乘客到 ...

  8. Island Transport

    Island Transport http://acm.hdu.edu.cn/showproblem.php?pid=4280 Time Limit: 20000/10000 MS (Java/Oth ...

  9. HDU4280:Island Transport(最大流)

    Island Transport Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

随机推荐

  1. 用Excel生成Sql

    用Excel生成Sql: 以如图为例:点击一行数据的后面一个单元格,在上面的fx部分输入=,以等号开头证明这是一个公式.在等号的后面写上想要添加的数据,书写规范是这样:'"&A2&a ...

  2. Vuex.js状态管理共享数据 - day8

    VScode文件目录: amount.vue代码如下: <template> <div> <!-- <h3>{{ $store.state.count }}& ...

  3. 详解ASP.NET缓存机制

    文中对ASP.NET的缓存机制进行了简述,ASP.NET中的缓存极大的简化了开发人员的使用,如果使用得当,程序性能会有客观的提升.缓存是在内存存储数据的一项技术,也是ASP.NET中提供的重要特性之一 ...

  4. webstorm使用总结

    1.webstorm显示ES6语法错误,和nodejs语法错误未提示的问题,只需要在 此处解决ES6语法错误问题: 此处解决不支持node语法的问题: 然后就显示正常啦.

  5. KVC/KVO 本质

    KVO 的实现原理 KVO是关于runtime机制实现的 当某个类的对象属性第一次被观察时,系统就会在运行期动态地创建该类的一个派生类,在这个派生类中重写基类中任何被观察属性的setter方法.派生类 ...

  6. codevs 1097 校门外的树 2005年NOIP全国联赛普及组 (线段树)

    时间限制: 1 s  空间限制: 128000 KB  题目等级 : 白银 Silver 题目描述 Description 某校大门外长度为L的马路上有一排树,每两棵相邻的树之间的间隔都是1米.我们可 ...

  7. -[UPAInitViewController startAPPay] in libUPAPayPlugin.a(UPAInitViewController.o)

    问题 Undefined symbols for architecture arm64: "_PKPaymentNetworkChinaUnionPay", referenced ...

  8. Python进程间通信和网络基础

    Python进程间通信和网络基础 Python支持多种进程间通讯的方式, 有单机通信的signal和mmap等, 也有可以通过网络的socket方式, 这里先介绍select等的有关知识, socke ...

  9. aspose.cell 给excel表格设置样式

    方法1: Style styleTitle = workbook.Styles[workbook.Styles.Add()];//新增样式 styleTitle.HorizontalAlignment ...

  10. 美国司法部解禁guns打印技术

    今日导读 你知道什么是 3D 打印吗?简单的说,只要有一张设计蓝图和适当的材料,就可以快速打印出实体物件.而最近据外媒报道,从今年 8 月 1 日起,在美国,拥有或公布枪支 3D 打印蓝图的行为都将属 ...