Problem Solving report UVA820 Internet Bandwidth

Source: Internet
Author: User

Problem Solving report UVA820 Internet Bandwidth

Description


On the Internet, Machines (nodes) is richly interconnected, and many paths may exist between a given pair of nodes. The total message-carrying capacity (bandwidth) between, given nodes is the maximal amount of data per unit time that C An IS transmitted from one node to the other. Using a technique called packet switching, this data can is transmitted along several paths at the same time.

For example, the following figure shows a network with four nodes (shown as circles), with a total of five connections amo ng them. Every connection is labeled with a bandwidth that represents its data-carrying capacity per unit time.

In our example, the bandwidth between node 1 and Node 4 are, which might be thought of as the sum of the bandwidths a Long the path 1-2-4, along the path 1-3-4, and 5 along the path 1-2-3-4. No other combination of paths between nodes 1 and 4 provides a larger bandwidth.

You must write a program that computes the bandwidth between and given nodes in a network, given the individual bandwidths The connections in the network. In this problem, assume that the bandwidth of a connection are always the same in both directions (which are not necessarily True in the real world).

Input

The input file contains descriptions of several networks. Every description starts with a line containing a single integer n (2≤n≤100), which are the number of nodes in the Networ K. The nodes is numbered from 1 to N. The next line contains three numbers s, T, and C. The numbers s and T is the source and destination nodes, and the number C was the total number of connections in the Netwo Rk. Following this is C lines describing the connections. Each of these lines contains three integers:the first and the numbers of the connected, and the nodes number is The bandwidth of the connection. The bandwidth is a non-negative number not greater than 1000.

There might is more than one connection between a pair of nodes, but a node cannot is connected to itself. All connections is bi-directional, i.e. data can be transmitted in both directions along a connection, but the sum of the Amount of data transmitted in both directions must is less than the bandwidth.

A line containing the number 0 follows the last network description, and terminates the input.

Output

For each network description, first print the number of the network. Then print the total bandwidth between the source node s and the destination node T, following the format of the sample OU Tput. Print a blank line after each test case.


Output for the
Sample Input Sample Input
41 4 51 2 201 3 102 3 52 4 103 4 200
Network 1The Bandwidth is 25.

ACM World Finals, problem E


The main topic: there is a computer network, the number of input nodes n, input network flow source and sink point src,des, and then enter the number of two-way side M. The load of the M-bar is given, and the maximum flow is obtained.


Analysis: Bare maximum flow, even the background is not packaged, and then directly hit the template to run the maximum flow can. Note The only pit point is that the output is going to be more than one line empty, and I haven't seen it. So the problem-solving report is over.


On the code:

#include <iostream> #include <cstdio> #include <algorithm> #include <queue> #include <  cstring>using namespace Std;const int maxm = 160000;const int MAXN = 400;const int INF = 0x3f3f3f3f;struct Edge{int to, Cap, next;}; Edge edge[maxm];int level[maxn];int head[maxn];int src, des, cnt;void addedge (int from, int. to, int cap) {edge[cnt].to = To;edge[cnt].cap = Cap;edge[cnt].next = Head[from];head[from] = Cnt++;swap (from, to); edge[cnt].to = To;edge[cnt].cap = C Ap;edge[cnt].next = Head[from];head[from] = cnt++;} int BFs () {memset (level,-1, sizeof level), Queue<int>q;while (!q.empty ()) Q.pop (); LEVEL[SRC] = 0;q.push (src); whil E (!q.empty ()) {int u = q.front (); Q.pop (); for (int i = head[u]; I! = 1; i = edge[i].next) {int v = edge[i].to;if (edge[i].c AP > 0 && level[v] = =-1) {Level[v] = Level[u] + 1;q.push (v);}}} return Level[des]! =-1;} int dfs (int u, int f) {if (U = = des) return f;int tem;for (int i = head[u]; I! =-1; i = edge[i].next) {int v = edge[i].toif (edge[i].cap>0&&level[v] = = Level[u] + 1) {tem = DFS (V, min (f, edge[i].cap)), if (Tem > 0) {edge[i].cap -= Tem;edge[i^1].cap + = Tem;return tem;}}} Level[u] = -1;return 0;} int dinic () {int ans = 0, Tem;while (BFS ()) {while (tem = DFS (src)) > 0) {ans + = tem;}} return ans;} int main () {int n, m;int kase = 1;while (cin >> n&&n) {memset (head,-1, sizeof head); cnt = 0;cin >> sr C >> des >> m;for (int i = 1; I <= m; i++) {int A, B, C;cin >> a >> b >> C;addedge (A, B, c);} printf ("Network%d\nthe bandwidth is%d.\n\n", kase++, Dinic ());} return 0;}

La La la la cheer, good sincerity of a problem.


Problem Solving report UVA820 Internet Bandwidth

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.