博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[Usaco2015 dec]Max Flow
阅读量:6160 次
发布时间:2019-06-21

本文共 2890 字,大约阅读时间需要 9 分钟。

Time Limit: 10 Sec  Memory Limit: 128 MB

Submit: 204  Solved: 129
[][][]

Description

Farmer John has installed a new system of N−1 pipes to transport milk between the N stalls in his barn (2≤N≤50,000), conveniently numbered 1…N. Each pipe connects a pair of stalls, and all stalls are connected to each-other via paths of pipes.

FJ is pumping milk between KK pairs of stalls (1≤K≤100,000). For the iith such pair, you are told two stalls sisi and titi, endpoints of a path along which milk is being pumped at a unit rate. FJ is concerned that some stalls might end up overwhelmed with all the milk being pumped through them, since a stall can serve as a waypoint along many of the KK paths along which milk is being pumped. Please help him determine the maximum amount of milk being pumped through any stall. If milk is being pumped along a path from sisi to titi, then it counts as being pumped through the endpoint stalls sisi and titi, as well as through every stall along the path between them.

给定一棵有N个点的树,所有节点的权值都为0。

有K次操作,每次指定两个点s,t,将s到t路径上所有点的权值都加一。

请输出K次操作完毕后权值最大的那个点的权值。

Input

The first line of the input contains NN and KK.

The next N−1 lines each contain two integers x and y (x≠y,x≠y) describing a pipe between stalls x and y.
The next K lines each contain two integers ss and t describing the endpoint stalls of a path through which milk is being pumped.

Output

An integer specifying the maximum amount of milk pumped through any stall in the barn.

Sample Input

5 10
3 4
1 5
4 2
5 4
5 4
5 4
3 5
4 3
4 3
1 3
3 5
5 4
1 5
3 4

Sample Output

9

Source

思路

树链剖分

代码实现

1 #include
2 const int maxn=5e4+10; 3 inline int min_(int x,int y){
return x
y?x:y;} 5 inline int swap_(int&x,int&y){x^=y,y^=x,x^=y;} 6 int n,k; 7 int a,b; 8 int eh[maxn],hs,et[maxn<<1],en[maxn<<1]; 9 int pd[maxn],pf[maxn],pws[maxn],psz[maxn],pps,pp[maxn],pt[maxn];10 int ts[maxn<<2],tf[maxn<<2];11 void dfs1(int k,int f,int d){12 psz[k]=1,pd[k]=d,pf[k]=f;13 for(int i=eh[k];i;i=en[i])14 if(et[i]!=f){15 dfs1(et[i],k,d+1);16 psz[k]+=psz[et[i]];17 if(psz[et[i]]>psz[pws[k]]) pws[k]=et[i];18 }19 }20 void dfs2(int k,int t){21 pp[k]=++pps,pt[k]=t;22 if(pws[k]) dfs2(pws[k],t);23 for(int i=eh[k];i;i=en[i])24 if(et[i]!=pf[k]&&et[i]!=pws[k])25 dfs2(et[i],et[i]);26 }27 void down(int k){28 int ls=k<<1,rs=ls|1;29 ts[ls]+=tf[k],ts[rs]+=tf[k];30 tf[ls]+=tf[k],tf[rs]+=tf[k];31 tf[k]=0;32 }33 void change(int k,int l,int r,int al,int ar){34 if(l==al&&r==ar){ts[k]++,tf[k]++;return;}35 if(tf[k]) down(k);36 int mid=l+r>>1,ls=k<<1,rs=ls|1;37 if(al<=mid) change(ls,l,mid,al,min_(ar,mid));38 if(ar>mid) change(rs,mid+1,r,max_(al,mid+1),ar);39 ts[k]=max_(ts[ls],ts[rs]);40 }41 int main(){42 scanf("%d%d",&n,&k);43 for(int i=1;i

 

转载于:https://www.cnblogs.com/J-william/p/6972568.html

你可能感兴趣的文章
第二章
查看>>
android背景选择器selector用法汇总
查看>>
[转]Paul Adams:为社交设计
查看>>
showdialog弹出窗口刷新问题
查看>>
java
查看>>
Vue.js连接后台数据jsp页面  ̄▽ ̄
查看>>
关于程序的单元测试
查看>>
mysql内存优化
查看>>
都市求生日记第一篇
查看>>
Java集合---HashMap源码剖析
查看>>
SQL优化技巧
查看>>
thead 固定,tbody 超出滚动(附带改变滚动条样式)
查看>>
Dijkstra算法
查看>>
css 动画 和 响应式布局和兼容性
查看>>
csrf 跨站请求伪造相关以及django的中间件
查看>>
MySQL数据类型--与MySQL零距离接触2-11MySQL自动编号
查看>>
生日小助手源码运行的步骤
查看>>
Configuration python CGI in XAMPP in win-7
查看>>
bzoj 5006(洛谷 4547) [THUWC2017]Bipartite 随机二分图——期望DP
查看>>
CF 888E Maximum Subsequence——折半搜索
查看>>