2013-2014 ACM-ICPC, NEERC, Southern Subregional Contest Problem I. Plugs and Sockets 费用流

时间:2021-12-19 09:00:05

Problem I. Plugs and Sockets

题目连接:

http://www.codeforces.com/gym/100253

Description

The Berland Regional Contest will be held in the main hall of the Berland State University. The university

has a real international status. That's why the power sockets in the main hall are not of the same type.

Some power sockets use the Berland standard of 330 volts at 40 Hz, but other sockets use the Beuropean

standard of 125 volts at 60 Hz.

The technical committee has n computers of three types. The computers of the rst type have power

plugs to plug them in Berland sockets (of 330 volts), the computers of the second type have plugs to plug

them in Beuropean sockets (of 125 volts). The most universal type is the third type, they can be plugged

into any socket, it doesn't matter if the socket uses the Berland standard or the Beuropean standard.

Also the computers dier by power consumption, the i-th computer consumes wi watts per hour.

The technical committee has to solve a dicult problem. Which computers should they use and how to

plug them in the order to maximize the number of plugged computers? A single socket can be used for at

most one plug. If there are many ways to choose the maximum number of computers to plug, the technical

committee wants to nd the way to minimize the total power consumption of the chosen computers.

Input

The rst line of the input contains n, a and b (1 ≤ n ≤ 5000; 0 ≤ a, b ≤ 5000) the number of computers

the technical committee has, the number of Berland standard sockets and the number of Beuropean

standard sockets in the hall. The following n lines contain computers' descriptions, one description per

line. Each description is a pair of two positive integer numbers ti and wi (1 ≤ ti ≤ 3; 1 ≤ wi ≤ 5000)

the type of the i-th computer and its power consumption.

Output

On the rst line print the maximum number of computers that can be plugged and the required minimum

total power consumption. Then print a single line for each plugged computer with two integer numbers

j and fj (1 ≤ j ≤ n; 1 ≤ fj ≤ a + b) meaning that the j-th computer should be connected to the fj -th

socket. The computers are numbered from 1 to n in the order of the input and sockets are numbered from

1 to a + b in such way that the rst a sockets use the Berland standard and the sockets a + 1, a + 2, . . . ,

a + b use the Beuropean standard. Print the lines in any order. If there are multiple answers, print any of

them.

Sample Input

5 1 2

1 2

1 1

3 10

2 20

2 15

Sample Output

3 26

2 1

5 2

3 3

Hint

题意

裸的费用流

题解:

代码

#include <bits/stdc++.h>
#define rep(a,b,c) for(int (a)=(b);(a)<=(c);++(a))
#define drep(a,b,c) for(int (a)=(b);(a)>=(c);--(a))
#define pb push_back
#define mp make_pair
#define sf scanf
#define pf printf
#define two(x) (1<<(x))
#define clr(x,y) memset((x),(y),sizeof((x)))
#define dbg(x) cout << #x << "=" << x << endl;
const int mod = 1e9 + 7;
int mul(int x,int y){return 1LL*x*y%mod;}
int qpow(int x , int y){int res=1;while(y){if(y&1) res=mul(res,x) ; y>>=1 ; x=mul(x,x);} return res;}
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}
using namespace std; struct ZKW_MinCostMaxFlow{ const static int maxn = 1e5 + 50;
const static int maxE = 1e5 + 50;
const static int INF = 0x3f3f3f3f; struct Edge{
int to,next,cap,flow,cost;
Edge(int _to=0,int _next=0,int _cap=0,int _flow=0,int _cost=0):
to(_to),next(_next),cap(_cap),flow(_flow),cost(_cost){}
}edge[maxE * 2]; int head[maxn],tot;
int cur[maxn];
int dis[maxn];
bool vis[maxn];
int ss,tt,N;
int min_cost,max_flow;
void init(int N){
tot=0;
for( int i = 0 ; i < N ; ++ i ) head[i] = -1;
}
int addedge(int u,int v,int cap,int cost){
edge[tot]=Edge(v,head[u],cap,0,cost);
int rs = tot;
head[u]=tot++;
edge[tot]=Edge(u,head[v],0,0,-cost);
head[v]=tot++;
return rs;
}
int aug(int u,int flow){
if(u==tt) return flow;
vis[u]=true;
for(int i=cur[u];i!=-1;i=edge[i].next){
int v=edge[i].to;
if( edge[i].cap>edge[i].flow && !vis[v] && dis[u]==dis[v]+edge[i].cost ){
int tmp=aug(v,min(flow,edge[i].cap-edge[i].flow));
edge[i].flow+=tmp;
edge[i^1].flow-=tmp;
cur[u]=i;
if(tmp) return tmp;
}
}
return 0;
}
bool modify_label(){
int d=INF;
for(int u=0;u<N;u++){
if(vis[u])
for(int i=head[u];i!=-1;i=edge[i].next){
int v=edge[i].to;
if(edge[i].cap>edge[i].flow && !vis[v])
d=min(d,dis[v]+edge[i].cost-dis[u]);
}
}
if(d==INF) return false;
for(int i=0;i<N;i++)
if(vis[i]){
vis[i]=false;
dis[i]+=d;
}
return true;
}
pair < int , int > mincostmaxflow(int start,int ed,int n ){
ss=start,tt=ed,N=n;
min_cost=max_flow=0;
for(int i=0;i<n;i++) dis[i]=0;
while(1){
for(int i=0;i<n;i++) cur[i]=head[i];
while(1){
for(int i=0;i<n;i++) vis[i]=false;
int tmp=aug(ss,INF);
if(tmp==0) break;
max_flow+=tmp;
min_cost+=tmp*dis[ss];
}
if(!modify_label()) break;
}
return mp( max_flow , min_cost );
}
}solver; int N , A , B ;
int TA = N + 1 , TB = N + 2 , T = N + 3 , S =0 ;
vector < int > idx[ 6500 ]; int main( int argc , char * argv[] ){
//freopen("in.txt","r",stdin);
N=read(),A=read(),B=read();
TA = N + 1 , TB = N + 2 , T = N + 3 , S = 0;
solver.init( N + 50 );
solver.addedge( TA , T , A , 0);
solver.addedge( TB , T , B , 0);
rep(i,1,N){
solver.addedge( S , i , 1 , 0 );
int tp = read() , w = read();
if( tp == 1 ) idx[i].pb(solver.addedge( i , TA , 1 , w ));
else if( tp == 2 ) idx[i].pb(solver.addedge( i , TB , 1 , w ));
else{
idx[i].pb(solver.addedge( i , TA , 1 , w ));
idx[i].pb(solver.addedge( i , TB , 1 , w ));
}
}
pair < int , int > ans = solver.mincostmaxflow( S , T , N + 50 );
pf("%d %d\n" , ans.first , ans.second );
int fa = 0 , fb = A;
for(int i = 1 ; i <= N ; ++ i){
int targetv = -1;
for(auto it : idx[i]){
//cout << solver.edge[it].flow << endl;
if( solver.edge[it].flow == 1 ){
targetv = solver.edge[it].to;
break;
}
}
if( targetv == TA ) pf("%d %d\n" , i , ++ fa );
else if( targetv == TB ) pf("%d %d\n" , i , ++ fb );
}
return 0;
}

2013-2014 ACM-ICPC, NEERC, Southern Subregional Contest Problem I. Plugs and Sockets 费用流的更多相关文章

  1. 2018-2019 ICPC&comma; NEERC&comma; Southern Subregional Contest

    目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...

  2. Codeforces 2018-2019 ICPC&comma; NEERC&comma; Southern Subregional Contest

    2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...

  3. 2018-2019 ICPC&comma; NEERC&comma; Southern Subregional Contest &lpar;Online Mirror&rpar; Solution

    从这里开始 题目列表 瞎扯 Problem A Find a Number Problem B Berkomnadzor Problem C Cloud Computing Problem D Gar ...

  4. Codeforces1070 2018-2019 ICPC&comma; NEERC&comma; Southern Subregional Contest &lpar;Online Mirror&comma; ACM-ICPC Rules&comma; Teams Preferred&rpar;总结

    第一次打ACM比赛,和yyf两个人一起搞事情 感觉被两个学长队暴打的好惨啊 然后我一直做*题,yyf一直在切神仙题 然后放一波题解(部分) A. Find a Number LINK 题目大意 给你 ...

  5. codeforce1070 2018-2019 ICPC&comma; NEERC&comma; Southern Subregional Contest &lpar;Online Mirror&comma; ACM-ICPC Rules&comma; Teams Preferred&rpar; 题解

    秉承ACM团队合作的思想懒,这篇blog只有部分题解,剩余的请前往星感大神Star_Feel的blog食用(表示男神汉克斯更懒不屑于写我们分别代写了下...) C. Cloud Computing 扫 ...

  6. 2018-2019 ICPC&comma; NEERC&comma; Southern Subregional Contest &lpar;Online Mirror&comma; ACM-ICPC Rules&comma; Teams Preferred&rpar;

    A. Find a Number 找到一个树,可以被d整除,且数字和为s 记忆化搜索 static class S{ int mod,s; String str; public S(int mod, ...

  7. 2018&period;10&period;20 2018-2019 ICPC&comma;NEERC&comma;Southern Subregional Contest&lpar;Online Mirror&comma; ACM-ICPC Rules&rpar;

    i207M的“怕不是一个小时就要弃疗的flag”并没有生效,这次居然写到了最后,好评=.= 然而可能是退役前和i207M的最后一场比赛了TAT 不过打得真的好爽啊QAQ 最终结果: 看见那几个罚时没, ...

  8. 2018-2019 ICPC&comma; NEERC&comma; Southern Subregional Contest &lpar;Online Mirror&comma; ACM-ICPC Rules&comma; Teams Preferred&rpar; Solution

    A. Find a Number Solved By 2017212212083 题意:$找一个最小的n使得n % d == 0 并且 n 的每一位数字加起来之和为s$ 思路: 定义一个二元组$&lt ...

  9. 【&ast;2000】【2018-2019 ICPC&comma; NEERC&comma; Southern Subregional Contest C 】Cloud Computing

    [链接] 我是链接,点我呀:) [题意] [题解] 我们可以很容易知道区间的每个位置有哪些安排可以用. 显然 我们优先用那些花费的钱比较少的租用cpu方案. 但一个方案可供租用的cpu有限. 我们可以 ...

随机推荐

  1. favicon的制作

    在head中插入如下标签: <link rel="shortcut icon" href="favicon.ico" />.然后把图标命名为favi ...

  2. php email邮箱正则验证

    国际域名格式如下: 域名由各国文字的特定字符集.英文字母.数字及“-”(即连字符或减号)任意组合而成, 但开头及结尾均不能含有“-”,“-”不能连续出现 . 域名中字母不分大小写.域名最长可达60个字 ...

  3. UVALive 5983 MAGRID

    题意:在一个n*m的网格上,从(0,0)走到(n-1,m-1),每次只能向右或者向下走一格.一个人最初有一个生命值x,走到每一个格生命值会变为x + s[i][j],(s[i][j]可为负,0,正), ...

  4. sql中select语句的逻辑执行顺序

    下面是SELECT语句的逻辑执行顺序: FROMONJOINWHEREGROUP BYWITH CUBE or WITH ROLLUPHAVINGSELECTDISTINCTORDER BYTOP M ...

  5. Vim配置说明

    使用这些天一直vim,我认为vim这是一个非常强大的编辑器,尤其是后配置. 互联网参考大牛个月vim配置,然后更改加入了一部分,形成了自己的配置.让Vim变的更强大. 详细有下面几个特点: 1.自己主 ...

  6. python 之金玉良言 或许是最后一次给自己系统总结--已结

    jar tvf xxx.jar vim xxx.jar 配置一下 notepad++ F5 cmd /k D:"Program Files (x86)"\python\python ...

  7. c&num; LINQ 使用

    linq是个好东西,让开发人员省时省力.很多人可能只知道怎么使用, 对它没有全面深入的了解.所谓磨刀不误砍柴工,今天就来学习下. 一.与LINQ有关的语言特性 1.扩展方法 在System.Linq命 ...

  8. HDU 4123 Bob’s Race(RMQ)

    题意是说给出一棵树,N(10^5)个顶点,以及每条边的权值,现在需要选择连续的K个点(顶点编号连续),可以被选出来的条件是: 若d[i]代表顶点i到树上其他点的距离的最大值,使得区间[a, b]的d值 ...

  9. python学习之winreg模块

    winreg模块将Windows注册表API暴露给了python. 常见方法和属性 winreg.OpenKey(key,sub_key,reserved = ,access = KEY_READ) ...

  10. java-mybaits-00503-延迟加载

    1.什么是延迟加载 resultMap可以实现高级映射(使用association.collection实现一对一及一对多映射),association.collection具备延迟加载功能. 需求: ...