spfa求图的最大流
2024-08-26 15:32:53
题目链接:
https://vjudge.net/contest/255738#problem/B
AC代码:
#include <iostream>
#include<vector>
#include<string>
#include<cstring>
#include<queue>
#include<stdio.h>
#define maxn 2000+10
using namespace std;
#define inf 0x3f3f3f3f
int n,m;
vector<pair<int,int > >q[maxn];
int vis[maxn];
int path[maxn];
int spfa()
{
for(int i=1; i<=n; i++)
{
vis[i]=0;
path[i]=0;
}
path[1]=inf;
vis[1]=1;
queue<int>w;
w.push(1);
int maxx=0;
while(!w.empty())
{
int top=w.front();
w.pop();
vis[top]=0;
maxx=max(maxx,path[n]);
if(path[top]<maxx)continue;
int len=q[top].size();
for(int i=0; i<len; i++)
{
int temp=q[top][i].first;
if(path[temp]<=path[top])
if(path[temp]<min(path[top],q[top][i].second)){
path[temp]=min(path[top],q[top][i].second);
if(path[temp]>maxx&&vis[temp]==0)
w.push(temp),vis[temp]=1;
}
}
}
return maxx;
}
int main()
{
int T;
int num=0;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
// cin>>n>>m;
for(int i=1; i<=n; i++)q[i].clear();
for(int i=1; i<=m; i++)
{
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
q[u].push_back(make_pair(v,w));
q[v].push_back(make_pair(u,w));
}
int ans=spfa();
printf("Scenario #%d:\n",++num);
printf("%d\n",ans);
printf("\n");
// cout<<"Scenario #"<<++num<<":"<<endl<<ans<<endl;
}
return 0;
}
最新文章
- 使用JSONObject.fromObject的时候出现“There is a cycle in the hierarchy”异常 的解决办法
- linux创建用户、设置密码、修改用户、删除用户
- Windows平台下ActiveMQ 安装
- js严格模式“use strict”
- ubuntu12.04安装mysql
- 关于SQL中的Update语句
- HDU 1561 树形DP(入门)
- powershell学习
- HDU-4115 Eliminate the Conflict 2sat
- (转) xcodebuild和xcrun自动化编译ipa包 笔记
- 模块化定义JS,让统一文件夹内相同的变量不冲突
- Swift与Objective-C API的交互
- 开发者需要了解的WebKit
- System Rules 更好的测试
- timesten报错:error while loading shared libraries: libaio.so.1: cannot open shared object file : No such file or directory
- linux 服务器时间同步
- Java并发编程的艺术&#183; 笔记(1)
- Rhino学习教程——1.4
- 用java开发dota英雄最华丽的技能
- 避免jquery的click多次绑定方法
热门文章
- 基于SSH框架的学生选课质量属性分析
- Alpha答辩总结
- XCODE 6.1.1 配置GLFW
- 虚拟主机修改上传配置(PHP)
- Linux用户管理简介
- LVS(Linus Virtual Server):三种负载均衡方式比较+另三种负载均衡方式
- blog 社会化评论插件 多说for china, disqus for global range
- SpringMvc+JavaConfig+Idea 基于JavaConfig搭建项目
- Gym - 101522H Hit!
- gitlab 7.10.4 去除邮件认证