USACO 2015 Dec Platinum 1.Max Flow
来源:互联网 发布:sql字符串截取 编辑:程序博客网 时间:2024/06/01 18:28
Description
Farmer John has installed a new system of
pipes to transport milk betweenthe stalls in his barn (), conveniently numbered. Each pipe connects a pair of stalls, and all stalls areconnected to each-other via paths of pipes.FJ is pumping milk between
pairs of stalls (). Fortheth such pair, you are told two stallsand, endpoints of apath along which milk is being pumped at a unit rate. FJ is concerned that somestalls might end up overwhelmed with all the milk being pumped through them,since a stall can serve as a waypoint along many of thepaths along whichmilk is being pumped. Please help him determine the maximum amount of milkbeing pumped through any stall. If milk is being pumped along a path fromto, then it counts as being pumped through the endpoint stallsand, as well as through every stall along the path between them.
Input
The first line of the input contains
and .The next
lines each contain two integers and() describing a pipebetween stalls and.
The next
lines each contain two integers anddescribing the endpointstalls of a path through which milk is being pumped.
Output
An integer specifying the maximum amount of milk pumped through any stall in thebarn.
Sample Input
5 103 41 54 25 45 45 43 54 34 31 33 55 41 53 4
Sample Output
9
#include<stdio.h>int n,k,x,y,s,t,r,ans,idx,point[500001],next[1000001],v[1000001],h[500001],fa[500001],sum[500001],size[500001],f[500001][21];void addedge(int x,int y){ next[++idx]=point[x]; point[x]=idx; v[idx]=y;}int max(int a,int b){ if(a>b) return a; return b;}void swap(int &m,int &k){ int o=m; m=k; k=o;}void dfs(int x,int y,int deep){ h[x]=deep; fa[x]=y; for (int i=1;i<17;i++) f[x][i]=f[f[x][i-1]][i-1]; for(int i=point[x];i;i=next[i]) if (v[i]!=y) { f[v[i]][0]=x; dfs(v[i],x,deep+1); }}int lca(int x,int y){ if(h[x]<h[y]) swap(x,y); for(int i=17;i>=0;i--) while (h[f[x][i]]>=h[y]) x=f[x][i]; if(x==y) return x; for(int i=17;i>=0;i--) if(f[x][i]!=f[y][i]) x=f[x][i],y=f[y][i]; return f[x][0];}void dfs2(int x,int fa){ size[x]=sum[x]; for(int i=point[x];i;i=next[i]) if(v[i]!=fa) { dfs2(v[i],x); size[x]+=size[v[i]]; } ans=max(ans,size[x]);}int main(){ scanf("%d%d",&n,&k); for(int i=1;i<n;i++) { scanf("%d%d",&x,&y); addedge(x,y); addedge(y,x); } dfs(1,0,1); for(int i=1;i<=k;i++) { scanf("%d%d",&s,&t); r=lca(s,t); sum[s]++; sum[t]++; sum[r]--; if(r!=1) sum[fa[r]]--; } dfs2(1,0); printf("%d\n",ans);}
阅读全文
3 0
- USACO 2015 Dec Platinum 1.Max Flow
- USACO 2015 Dec Platinum 1.Max Flow题解,
- [Usaco2015 dec]Max Flow
- bzoj4390【Usaco2015 Dec】Max Flow
- 【bzoj4390】[Usaco2015 dec]Max Flow
- bzoj4390: [Usaco2015 dec]Max Flow
- BZOJ 4390: [Usaco2015 dec]Max Flow|树链剖分
- BZOJ 4390: [Usaco2015 dec]Max Flow
- bzoj 4390: [Usaco2015 dec]Max Flow(树链剖分+手写栈)
- [BZOJ4390][Usaco2015 dec]Max Flow(树上差分+lca)
- 【bzoj 4390】 [Usaco2015 dec]Max Flow(树上差分)
- BZOJ 4390: [Usaco2015 dec]Max Flow 树链剖分/树上差分
- 【BZOJ】4390 [Usaco2015 dec]Max Flow LCA+树上差分
- USACO DEC12,Platinum
- USACO 2006 Dec TheFewestCoins
- USACO 2009 Dec Bobsledding
- USACO Dec. 09 过路费
- 【Usaco】2006 Dec
- iOS NSNotification和NSNotificationCenter的详解
- C# post数据时 一段时间后发生错误: System.Net.WebException: 操作超时
- 使用Visual Studio 2012 开发 Html5 应用
- Go工程目录介绍及go程序编译运行介绍
- static关键字
- USACO 2015 Dec Platinum 1.Max Flow
- svn操作
- Spring boot 整合websocket
- 不能再迷茫下去了,只有你付出才能有收获
- 共享单车竞争感悟
- 数据仓库建设
- Java的加密和解密艺术
- 界面的动画跳转
- 比较有用的网站