BZOJ4519: [Cqoi2016]不同的最小割
Description
Input
Output
输出文件第一行为一个整数,表示个数。
Sample Input
1 2 3
1 3 6
2 4 5
3 4 4
Sample Output
#include<cstdio>
#include<cctype>
#include<queue>
#include<cstring>
#include<algorithm>
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define ren for(int i=first[x];i!=-1;i=next[i])
using namespace std;
const int BufferSize=1<<16;
char buffer[BufferSize],*head,*tail;
inline char Getchar() {
if(head==tail) {
int l=fread(buffer,1,BufferSize,stdin);
tail=(head=buffer)+l;
}
return *head++;
}
inline int read() {
int x=0,f=1;char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=getchar()) x=x*10+c-'0';
return x*f;
}
const int maxn=910;
const int maxm=20010;
struct Dinic {
struct Edge {int from,to,flow;}edges[maxm];
int n,m,s,t,first[maxn],next[maxm];
int d[maxn],vis[maxn],cur[maxn];
void init(int n) {
this->n=n;m=0;
memset(first,-1,sizeof(first));
}
void AddEdge(int u,int v,int w) {
edges[m]=(Edge){u,v,w};next[m]=first[u];first[u]=m++;
edges[m]=(Edge){v,u,w};next[m]=first[v];first[v]=m++;
}
void reset() {rep(i,0,m-1) edges[i].flow=edges[i^1].flow=(edges[i].flow+edges[i^1].flow)>>1;}
int Q[maxn],clo;
int BFS() {
int l=1,r=0;Q[++r]=s;vis[s]=++clo;
while(l<=r) {
int x=Q[l++];cur[x]=first[x];
ren {
Edge& e=edges[i];
if(e.flow&&vis[e.to]!=clo) {
vis[e.to]=clo;
d[e.to]=d[x]+1;
Q[++r]=e.to;
}
}
}
return vis[t]==clo;
}
int DFS(int x,int a) {
if(x==t||!a) return a;
int flow=0,f;
for(int& i=cur[x];i!=-1;i=next[i]) {
Edge& e=edges[i];
if(d[e.to]==d[x]+1&&(f=DFS(e.to,min(a,e.flow)))) {
e.flow-=f;edges[i^1].flow+=f;
flow+=f;a-=f;if(!a) break;
}
}
return flow;
}
int solve(int s,int t) {
this->s=s;this->t=t;int flow=0;
while(BFS()) flow+=DFS(s,1e9);
return flow;
}
}sol;
int cnt,A[maxn],tmp[maxn],ans[maxm];
void solve(int l,int r) {
if(l>=r) return;sol.reset();
ans[++cnt]=sol.solve(A[l],A[r]);
int L=l,R=r;
rep(i,l,r) {
if(sol.vis[A[i]]==sol.clo) tmp[L++]=A[i];
else tmp[R--]=A[i];
}
rep(i,l,r) A[i]=tmp[i];
solve(l,R);solve(L,r);
}
int main() {
int n=read(),m=read();sol.init(n);
rep(i,1,m) {
int a=read(),b=read(),c=read();
sol.AddEdge(a,b,c);
}
rep(i,1,n) A[i]=i;solve(1,n);
sort(ans+1,ans+cnt+1);
int res=1;
rep(i,2,cnt) if(ans[i]!=ans[i-1]) res++;
printf("%d\n",res);
return 0;
}
BZOJ4519: [Cqoi2016]不同的最小割的更多相关文章
- bzoj千题计划140:bzoj4519: [Cqoi2016]不同的最小割
http://www.lydsy.com/JudgeOnline/problem.php?id=4519 最小割树 #include<queue> #include<cstdio&g ...
- bzoj4519: [Cqoi2016]不同的最小割(分治最小割)
4519: [Cqoi2016]不同的最小割 题目:传送门 题解: 同BZOJ 2229 基本一样的题目啊,就最后用set记录一下就ok 代码: #include<cstdio> #inc ...
- [bzoj4519][Cqoi2016]不同的最小割_网络流_最小割_最小割树
不同的最小割 bzoj-4519 Cqoi-2016 题目大意:题目链接. 注释:略. 想法: 我们发现这和最小割那题比较像. 我们依然通过那个题说的办法一样,构建最小割树即可. 接下来就是随便怎么处 ...
- BZOJ4519 CQOI2016不同的最小割(最小割+分治)
最小割树:新建一个图,包含原图的所有点,初始没有边.任取两点跑最小割,给两点连上权值为最小割的边,之后对于两个割集分别做同样的操作.最后会形成一棵树,树上两点间路径的最小值即为两点最小割.证明一点都不 ...
- BZOJ4519——[cqoi2016]不同的最小割
0.题意:求两点之间的最小割的不同的总量 1.分析:裸的分治+最小割,也叫最小割树或GH树,最后用set搞一下就好 #include <set> #include <queue> ...
- BZOJ4519[Cqoi2016]不同的最小割——最小割树+map
题目描述 学过图论的同学都知道最小割的概念:对于一个图,某个对图中结点的划分将图中所有结点分成 两个部分,如果结点s,t不在同一个部分中,则称这个划分是关于s,t的割.对于带权图来说,将 所有顶点处在 ...
- bzoj4519: [Cqoi2016]不同的最小割(最小割树)
传送门 好神仙……最小割树是个什么东西…… 其实我觉得干脆直接$O(n^2)$跑几个dinic算了…… 来说一下这个叫最小割树的神奇东西 我们先建一个$n$个点,没有边的无向图 在原图中任选两点$s, ...
- 【BZOJ4519】[Cqoi2016]不同的最小割 最小割树
[BZOJ4519][Cqoi2016]不同的最小割 Description 学过图论的同学都知道最小割的概念:对于一个图,某个对图中结点的划分将图中所有结点分成两个部分,如果结点s,t不在同一个部分 ...
- 【BZOJ-4519】不同的最小割 最小割树(分治+最小割)
4519: [Cqoi2016]不同的最小割 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 393 Solved: 239[Submit][Stat ...
随机推荐
- poj 3278:Catch That Cow(简单一维广搜)
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 45648 Accepted: 14310 ...
- 【openGL】画正弦函数图像
#include "stdafx.h" #include <GL/glut.h> #include <stdlib.h> #include <math ...
- RAC NTP/CTSS
本文總結主要參考: http://blog.itpub.net/23135684/viewspace-759693/ http://www.happyworld.net.cn/post/6.html ...
- golang channel basic
package mainimport ( "fmt" "math/rand" "time")func main() { rand.Seed( ...
- Mysql常用命令详解
Mysql安装目录 数据库目录 /var/lib/mysql/ 配置文件 /usr/share/mysql(mysql.server命令及配置文件) 相关命令 /usr/bin(mysqladmin ...
- Android开发如何去除标题栏title(转)
去除标题栏title其实非常简单,他有两种方法,一种是在代码中添加,另一种是在AndroidManifest.xml中添加: 1.在代码中实现:在此方法setContentView(R.layout. ...
- 在Salesforce中编写Unit Test
Unit Test 也是一个 Class 文件,所以在创建 Unit Test 的时候要选择 Test Class 类型来创建,请看如下截图(在Eclipse中): 编写 Unit Test 基本流程 ...
- Codeforces Round #161 (Div. 2) D. Cycle in Graph(无向图中找指定长度的简单环)
题目链接:http://codeforces.com/problemset/problem/263/D 思路:一遍dfs即可,dp[u]表示当前遍历到节点u的长度,对于节点u的邻接点v,如果v没有被访 ...
- MATLAB中stem函数用法
stem(Y) 将数据序列Y从x轴到数据值按照茎状形式画出,以圆圈终止.如果Y是一个矩阵,则将其每一列按照分隔方式画出. stem(X,Y)在X的指定点处画出数据序列Y. stem(...,'fil ...
- zookeeper源码分析二FASTLEADER选举算法
如何在zookeeper集群中选举出一个leader,zookeeper使用了三种算法,具体使用哪种算法,在配置文件中是可以配置的,对应的配置项是"electionAlg",其中1 ...