Power Network [POJ - 1459]
题解:
最大流模板题
dinic算法
建立一个超级源点跟超级汇点,把超级源点连接到发电厂,流量设为发电厂发电量
超级汇点跟耗电的用户连接,流量为消耗的电能
发电场和消耗电能的工厂用题目所给数据连接即可。
再跑一边dinic
/*Keep on going Never give up*/
#pragma GCC optimize(3,"Ofast","inline")
#include <iostream>
#include <cstdio>
#include <stdlib.h>
#include <cstring>
#include <cmath>
#include <math.h>
#include <string>
#include<string.h>
#include <list>
#include <set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <cctype>
#include<iomanip>
//#define int long long
#define endl '\n'
using namespace std;
const int maxn = 1e6+10;
const int MaxN = 0x3f3f3f3f;
const int MinN = 0xc0c0c00c;
typedef long long ll;
const ll mod= 199999;
using namespace std;
int n,nc,np,m;
struct node{int u,v,cap,next;
}edge[maxn];
int head[maxn],dis[maxn];
int cnt=0,cur[maxn];
//int sp=0,tp=n+1;
void init(){memset(head,-1,sizeof head);cnt=0;
}void add(int u,int v,int w){edge[cnt].u=u,edge[cnt].v=v,edge[cnt].cap=w;edge[cnt].next=head[u],head[u]=cnt++;edge[cnt].u=v,edge[cnt].v=u,edge[cnt].cap=0;edge[cnt].next=head[v],head[v]=cnt++;
}bool bfs(){memset(dis,-1,sizeof dis);queue<int> q;dis[0]=0;q.push(0);while(!q.empty()){int u=q.front();q.pop();for(int i=head[u];~i;i=edge[i].next){int to=edge[i].v;int w=edge[i].cap;if(dis[to]==-1&&w>0){dis[to]=dis[u]+1;q.push(to);if(to==n+1) break;}}}return dis[n+1]!=-1;}int dfs(int u,int cap){if(u==n+1||cap==0) return cap;int res=0,f;for(int &i=cur[u];~i;i=edge[i].next){int to=edge[i].v;int w=edge[i].cap;if(dis[to]==dis[u]+1&&(f=dfs(to,min(cap-res,w)))>0){edge[i].cap-=f;edge[i^1].cap+=f;res+=f;if(res==cap) return cap;}}//if(!res) dis[u]=-1;return res;
}int dinic(){int ans=0;while(bfs()){//cout<<ans<<endl;for(int i=0;i<=n+1;i++){cur[i]=head[i];}ans+=dfs(0,MaxN);}return ans;
}signed main(){while(cin>>n>>np>>nc>>m){init();for(int i=0;i<m;i++){int u,v,w;scanf(" (%d,%d)%d",&u,&v,&w);u++,v++;add(u,v,w);}for(int i=0;i<np;i++){int u,w;scanf(" (%d)%d",&u,&w);u++;add(0,u,w);}for(int i=0;i<nc;i++){int u,w;scanf(" (%d)%d",&u,&w);u++;add(u,n+1,w);}//cout<<22<<endl;cout<<dinic()<<endl;}return 0;
}
Power Network [POJ - 1459]相关推荐
- Power Network POJ - 1459(EK算法模板+详解)
题意: 总共有a个节点,其中有发电站b个.用户c个和调度器a-b-c个三种节点,每个发电站有一个最大发电量,每个用户有个最大接受电量,现在有d条有向边,边有一个最大的流量代表,最多可以流出这么多电,现 ...
- POJ 1459 -- Power Network(最大流, 建图)
题目链接 Description A power network consists of nodes (power stations, consumers and dispatchers) conne ...
- 【POJ - 1459】Power Network(网络流最大流,建图)
题干: A power network consists of nodes (power stations, consumers and dispatchers) connected by power ...
- Poj(1459),最大流,EK算法
题目链接:http://poj.org/problem?id=1459 Power Network Time Limit: 2000MS Memory Limit: 32768K Total Su ...
- [Poj 1459] 网络流(一) {基本概念与算法}
{ 凸包的内容还欠整理 先来侃侃一个月以前就想写写的网络流 本文介绍网络流 网络流的算法 及其应用 这些问题没事想想还是很有意思的 } ================================ ...
- A - Wireless Network POJ - 2236
A - Wireless Network POJ - 2236 并查集 if (op == 'S') {scanf("%d%d", &u, &v);if(vis[u ...
- I-Matrix Power Series POJ - 3233 矩阵快速幂+分治
I-Matrix Power Series POJ - 3233 矩阵快速幂+分治 Problem Description Given a n × n matrix A and a positive ...
- POJ1459 Power Network —— 最大流
题目链接:https://vjudge.net/problem/POJ-1459 Power Network Time Limit: 2000MS Memory Limit: 32768K Tot ...
- 第二十七课:Power Network Synthesis(PNS)
总览 前面完成了IO pad 及macro cell的placement及congestion的消除,本节课开始说明PG network的放置并满足congestion与timing delay: 整 ...
最新文章
- 分布式事务:分布式事务原理概述
- 软件工程进度条-第十五周
- 【objectMapper实体转换异常】 com.fasterxml.jackson.databind.exc.MismatchedInputException
- c语言中调试时go的作用,C语言调用GO
- oracle 表空间初始分配,在 Oracle 中创建用户时,若未提及 DEFAULT TABLESPACE 关键字,则 Oracle 就将 ( )表空间分配给用户作为默认表空间。...
- A 附录、ResolvableType
- 强制应用 AMP 工具,开发者欲“封杀” Google!
- 【转】Windows和Ubuntu双系统,修复UEFI引导的两种办法
- 连续整数--全国模拟(一)
- 受限用户如何禁用迈克菲等开机自动启动软件?
- mozhe靶场——网络安全——投票系统程序设计缺陷分析
- powerVR使用说明
- 网页番茄钟(Pomodoro timer)
- 微信小程序--行星轨迹
- 腾讯“立知”被疑抄袭“即刻”
- 高德地图轨迹回放、点的弹跳效果、浏览器环境监测、设置地图的主题样式、GPS坐标转为高德坐标、地图加载提示、地图DOM事件、修改图层等API接口
- python中bool()函数的用法
- 清华大学的同学,究竟有多难?
- HTML+CSS网页设计期末课程大作——校园篮球网页(12页) 关于运动的HTML网页设计-----篮球
- 浩客XM:面对增长困局,抓体验真的有用吗?