LightOJ 1153 Internet Bandwidth

On the Internet, machines (nodes) are richly interconnected, and many paths may exist between a given pair of nodes. The total message-carrying capacity (bandwidth) between two given nodes is the maximal amount of data per unit time that can be transmitted from one node to the other. Using a technique called packet switching; this data can be 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 among 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 is 25, which might be thought of as the sum of the bandwidths 10 along the path 1-2-4, 10 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 two given nodes in a network, given the individual bandwidths of all the connections in the network. In this problem, assume that the bandwidth of a connection is always the same in both directions (which is not necessarily true in the real world).

Input

Input starts with an integer T (≤ 30), denoting the number of test cases.

Every description starts with a line containing an integer n (2 ≤ n ≤ 100), which is the number of nodes in the network. The nodes are numbered from 1 to n. The next line contains three numbers s, t, and c. The numbers s and t are the source and destination nodes, and the number c (c ≤ 5000, s ≠ t) is the total number of connections in the network. Following this are c lines describing the connections. Each of these lines contains three integers: the first two are the numbers of the connected nodes, and the third number is the bandwidth of the connection. The bandwidth is a non-negative number not greater than 1000.

There might be more than one connection between a pair of nodes, but a node cannot be connected to itself. All connections are 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 be less than the bandwidth.

Output

For each case of input, print the case number and the total bandwidth between the source node s and the destination node t.

Sample Input

Output for Sample Input

2

4

1 4 5

1 2 20

1 3 10

2 3 5

2 4 10

3 4 20

4

1 4 2

1 4 20

1 4 20

Case 1: 25

Case 2: 40

 

最大流入门,真的是最基础的了。。

给的边直接建图,跑一个最大流模板就好了,,

#include "cstring"
#include "iostream"
#include "cstdio"
#include "queue"
using namespace std;
typedef long long LL;
const int M=205;
const int maxn=2147483648;
const int INF = 0x3f3f3f3f;

int s,t,n,m;
int map[M][M],flow[M][M];
int p[M],a[M];
int EK(int s,int t)
{
    queue<int>q;
    int sum=0;
    memset(flow,0,sizeof(flow));
    while(1)
    {
        memset(a,0,sizeof(a));
        a[s]=INF;
        q.push(s);
        while(!q.empty())
        {
            int u=q.front();
            q.pop();
            for(int i=1; i<=m; i++)
            {
                if(!a[i]&&flow[u][i]<map[u][i])
                {
                    p[i]=u;
                    q.push(i);
                    a[i]=a[u]<map[u][i]-flow[u][i]?a[u]:map[u][i]-flow[u][i];
                }
            }
        }
        if(!a[t])
            break;
        for(int i=t; i!=s; i=p[i])
        {
            flow[p[i]][i]+=a[t];
            flow[i][p[i]]-=a[t];
        }
        sum+=a[t];
    }
    return sum;
}
int main()
{
    int casee=1;
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&m);
        scanf("%d%d%d",&s,&t,&n);
        memset(map,0,sizeof(map));
        int a,b,c;
        for(int i=0; i<n; i++)
        {
            scanf("%d%d%d",&a,&b,&c);
            map[a][b]+=c;
            map[b][a]=map[a][b];
        }
        int maxx=EK(s,t);
        cout<<"Case "<<casee++<<": "<<EK(s,t)<<endl;

    }

    return 0;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
毕业设计,基于SpringBoot+Vue+MySQL开发的课程作业管理系,源码+数据库+开题报告+论文答辩+毕业论文+视频演示 随着科学技术的飞速发展,社会的方方面面、各行各业都在努力与现代的先进技术接轨,通过科技手段来提高自身的优势,课程作业管理系统当然也不能排除在外。课程作业管理系统是以实际运用为开发背景,运用软件工程原理和开发方法,采用springboot框架构建的一个管理系统。整个开发过程首先对软件系统进行需求分析,得出系统的主要功能。接着对系统进行总体设计和详细设计。总体设计主要包括系统功能设计、系统总体结构设计、系统数据结构设计和系统安全设计等;详细设计主要包括系统数据库访问的实现,主要功能模块的具体实现,模块实现关键代码等。最后对系统进行功能测试,并对测试结果进行分析总结,得出系统中存在的不足及需要改进的地方,为以后的系统维护提供了方便,同时也为今后开发类似系统提供了借鉴和帮助。这种个性化的网上管理系统特别注重交互协调与管理的相互配合,激发了管理人员的创造性与主动性,对课程作业管理系统而言非常有利。 本课程作业管理系统采用的数据库是Mysql,使用springboot框架开发。在设计过程中,充分保证了系统代码的良好可读性、实用性、易扩展性、通用性、便于后期维护、操作方便以及页面简洁等特点。 1、关于课程作业管理系统的基本要求: (1)功能要求:可以管理首页、个人中心、公告信息管理、班级管理、学生管理、教师管理、课程类型管理、课程信息管理、学生选课管理、作业布置管理、作业提交管理、作业评分管理、课程评价管理、课程资源管理等功能模块。 (2)性能:在不同操作系统上均能无差错实现在不同类型的用户登入相应界面后能不出差错、方便地进行预期操作。 (3)安全与保密要求:用户都必须通过注册、登录才能进入系统,并且用户的权限也需要根据用户的类型进行限定。 (4)环境要求:支持多种平台,可在Windows系列、Vista系统等多种操作系统下使用。 关键词:课程作业管理系统,springboot框架; Mysql数据库 Java技术
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值