题目链接

Problem Description

  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

AC

  • 找到源点和汇点,裸的最大流
#include <iostream>
#include <stdio.h>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#define N 100005
#include <cstring>
#define ll long long
#define P pair<int, int>
#define mk make_pair
using namespace std;int n, m, cnt;
int inf = 0x3f3f3f3f;
int level[N];
struct ac{int v, c, pre;
}edge[N * 2];
int head[N], dis[N], curedge[N];
void init() {cnt = 0;memset(dis, -1, sizeof(dis));memset(edge, 0, sizeof(edge));memset(head, -1, sizeof(head));
}
void addedge(int u, int v, int c) {edge[cnt].v = v;edge[cnt].c = c;edge[cnt].pre = head[u];head[u] = cnt++;
}
bool bfs(int s, int e) {queue<int> que;memset(level, 0, sizeof(level));level[s] = 1;que.push(s);while (!que.empty()) {int u = que.front();que.pop();for (int i = head[u]; i != -1; i = edge[i].pre) {if (level[edge[i].v] == 0 && edge[i].c > 0) {level[edge[i].v] = level[u] + 1;que.push(edge[i].v);}}}return level[e] != 0;
}
int dfs(int s, int e, int flow) {if (s == e)return flow;for (int &i = curedge[s]; i != -1; i = edge[i].pre) {if (level[edge[i].v] == level[s] + 1 && edge[i].c > 0) {int d = dfs(edge[i].v, e, min(flow, edge[i].c));if (d > 0) {edge[i].c -= d;edge[i ^ 1].c += d;return d;}}}return 0;
}
int Dinic(int s, int e) {int ans = 0;while (bfs(s, e)) {for (int i = 1; i <= n; ++i) {curedge[i] = head[i];}int d;while (d = dfs(s, e, inf))ans += d;}return ans;
}int main() {
#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);
#endifint t;scanf("%d", &t);while (t--) {init();scanf("%d%d", &n, &m);int l = inf, r = -inf, s, e;for (int i = 1; i <= n; ++i) {int t1, t2;scanf("%d%d", &t1, &t2);if (l > t1) l = t1, s = i;if (r < t1) r = t1, e = i;}for (int i = 0; i < m; ++i) {int u, v, c;scanf("%d%d%d", &u, &v, &c);// 双向边 addedge(u, v, c);addedge(v, u, c);}int ans = Dinic(s, e);printf("%d\n", ans);}return 0;
}

HDU Problem - 4280 Island Transport(最大流)相关推荐

  1. HDU - 4280 Island Transport(最大流)

    题目链接:点击查看 题目大意:给出n个岛屿,由m条无向边连接而成,现在要从最西边的岛屿到达最东边的岛屿,问最大流量为多少 题目分析:最大流模板题,只不过这个毒瘤题卡掉了dinic,只能去网上找了个SA ...

  2. HDU Problem - 4289 Control(最大流)

    题目链接 Problem Description You, the head of Department of Security, recently received a top-secret inf ...

  3. HDU Problem - 4292 Food(最大流, 建边)

    题目链接 Problem Description You, a part-time dining service worker in your college's dining hall, are n ...

  4. hdu4280 Island Transport 网络流最大流 Dinic算法高效模板

    Island Transport In the vast waters far far away, there are many islands. People are living on the i ...

  5. HDU Problem - 1533 Going Home(费用流板子题)

    题目链接 Problem Description On a grid map there are n little men and n houses. In each unit time, every ...

  6. HDU Problem - 3338 Kakuro Extension (最大流,建图)

    题目链接 Problem Description If you solved problem like this, forget it.Because you need to use a comple ...

  7. HDU Problem - 2732 Leapin' Lizards(最大流,拆点建边)

    题目链接 Problem Description Your platoon of wandering lizards has entered a strange room in the labyrin ...

  8. HDU Problem 1272 小希的迷宫 【并查集】

    小希的迷宫 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  9. HDU Problem 2062 Bone Collector【01背包】

    Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

最新文章

  1. iSCSI的基础实验
  2. 2020年春季学期信号与系统课程作业参考答案-第十二次作业
  3. JavaScript实现backtracking Jump Game回溯跳跃游戏算法(附完整源码)
  4. 35岁中年博士失业,决定给找高校教职的后辈一些建议
  5. 公开说说别人看不到_当听到别人在说自己坏话时,心里是什么感受?
  6. MyEclipse生成常用方法
  7. springboot 打印slf4_SpringBoot 整合 slf4j 日志打印
  8. linux上NFS性能参数
  9. Mangos源码分析(15):游戏对象的实现
  10. (37)一个合理的时序约束方法
  11. python爬虫有道词典_Python爬取有道词典,有道的反爬很难吗?也就这样啊!
  12. 树形DP+DFS序+树状数组 HDOJ 5293 Tree chain problem(树链问题)
  13. Mysql 常用函数集
  14. js实现身份证号查询相关信息
  15. java实现qq页面登陆界面
  16. 解决ubuntu无法解析域名问题
  17. 设计模式C++描述----01.单例(Singleton)模式
  18. mysql ddl 导致tmp空间溢出并报错
  19. Netherlands central buffer of UPS european delivery center
  20. Opengl绘制网格模型

热门文章

  1. ACM学习历程—Hihocoder 1290 Demo Day(动态规划)
  2. 设计模式之: 装饰器模式
  3. SQL Server 索引结构及其使用(一)[转]
  4. 从n个数中随机选取m个
  5. 对于不返回任何键列信息的 SelectCommand 不支持 UpdateCommand 的动态 SQL 生成。
  6. 【数据结构与算法】之深入解析“灯泡开关”的求解思路与算法示例
  7. HarmonyOS之搭建和配置开发环境的流程
  8. Vue - Markdown编辑器
  9. Windows 下更换pip源为阿里源
  10. Ubuntu 启动或停止django服务