博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
洛谷——P3128 [USACO15DEC]最大流Max Flow
阅读量:4560 次
发布时间:2019-06-08

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

题目描述

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

FJ is pumping milk between  pairs of stalls (). For the th such pair, you are told two stalls  and , 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  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  to , then it counts as being pumped through the endpoint stalls  and

, as well as through every stall along the path between them.

FJ给他的牛棚的N(2≤N≤50,000)个隔间之间安装了N-1根管道,隔间编号从1到N。所有隔间都被管道连通了。

FJ有K(1≤K≤100,000)条运输牛奶的路线,第i条路线从隔间si运输到隔间ti。一条运输路线会给它的两个端点处的隔间以及中间途径的所有隔间带来一个单位的运输压力,你需要计算压力最大的隔间的压力是多少。

输入输出格式

输入格式:

 

The first line of the input contains  and .

The next  lines each contain two integers  and  () describing a pipe

between stalls  and .

The next  lines each contain two integers  and  describing the endpoint

stalls of a path through which milk is being pumped.

 

输出格式:

 

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

barn.

 

输入输出样例

输入样例#1:
5 103 41 54 25 45 45 43 54 34 31 33 55 41 53 4
输出样例#1:
9

 

树剖+树上查分

1 #include 
2 #include
3 4 using namespace std; 5 6 const int N(50000+15); 7 int n,k,u,v; 8 9 int head[N],sumedge;10 struct Edge11 {12 int v,next;13 Edge(int v=0,int next=0):14 v(v),next(next){}15 }edge[N<<1];16 void ins(int u,int v)17 {18 edge[++sumedge]=Edge(v,head[u]);19 head[u]=sumedge;20 }21 22 int size[N],deep[N],dad[N],top[N];23 void DFS(int x)24 {25 size[x]=1; deep[x]=deep[dad[x]]+1;26 for(int i=head[x];i;i=edge[i].next)27 {28 int v=edge[i].v;29 if(dad[x]==v) continue;30 dad[v]=x; DFS(v); size[x]+=size[v];31 }32 }33 void DFS_(int x)34 {35 int t=0; if(!top[x]) top[x]=x;36 for(int i=head[x];i;i=edge[i].next)37 {38 int v=edge[i].v;39 if(dad[x]!=v&&size[t]

 

转载于:https://www.cnblogs.com/Shy-key/p/7202168.html

你可能感兴趣的文章
【NOIP1999】【Luogu1015】回文数(高精度,模拟)
查看>>
Linux上安装Python3.5
查看>>
crt安装
查看>>
git切换分支报错:error: pathspec 'origin/XXX' did not match any file(s) known to git
查看>>
c++中static的用法详解
查看>>
转 我修改的注册表,但是程序运行起来,还是记着以前的
查看>>
图片轮播功能
查看>>
第六周小组作业:软件测试和评估
查看>>
linux Cacti监控服务器搭建
查看>>
debian(kali Linux) 安装net Core
查看>>
centos 7防火墙设置
查看>>
自定义进度条(圆形、横向进度条)
查看>>
spark-streaming-kafka采坑
查看>>
9.Mongodb与python交互
查看>>
18-[JavaScript]-函数,Object对象,定时器,正则表达式
查看>>
读取短信回执
查看>>
EF 数据初始化
查看>>
PreparedStatement与Statement
查看>>
WebService -- Java 实现之 CXF ( 使用CXF工具生成client 程序)
查看>>
Android学习--网络通信之网络图片查看器
查看>>