日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

HDU Problem - 4280 Island Transport(最大流)

發(fā)布時間:2024/4/18 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDU Problem - 4280 Island Transport(最大流) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題目鏈接

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; }

總結(jié)

以上是生活随笔為你收集整理的HDU Problem - 4280 Island Transport(最大流)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。