其实我觉得这种题目风格很像今天省选第三轮D1T1

都是在一个算法模型上去探索规律;

首先我们要做一遍最大流毫无疑问

第一问看起来很好想,只要是满流边就可以了?

错,反例不难找到

如:1--->2 flow 4

2--->3 flow 4

3--->1 flow 4

1--->4 flow 4

很有可能我们在找增广路的时候,走了多余的回路(1-2-3-1),导致前3条边也是满流边,但不会出现在最小割方案中

所以我们考虑用tarjan对残留网络缩点;

对于第一问,要求是满流边且起点终点在不同集合

第二问,显然在满足第一问的前提下,起点终点分属源点汇点集合

 const inf=;
type node=record
       from,point,next,flow:longint;
     end; var edge:array[..] of node;
    ans1,ans2:array[..] of longint;
    p,cur,pre,numh,h,low,dfn,be,st:array[..] of longint;
    tot,d,r,x,y,z,i,j,n,m,s,t,len:longint;
    v,f:array[..] of boolean; function min(a,b:longint):longint;
  begin
    if a>b then exit(b) else exit(a);
  end; procedure add(x,y,f:longint);
  begin
    inc(len);
    edge[len].point:=y;
    edge[len].from:=x;
    edge[len].flow:=f;
    edge[len].next:=p[x];
    p[x]:=len;
  end; procedure sap;
  var u,i,j,tmp,neck,q:longint;
  begin
    u:=s;
    numh[]:=n;
    while h[s]<n do
    begin
      if u=t then
      begin
        i:=s;
        neck:=inf;
        while i<>t do
        begin
          j:=cur[i];
          if neck>edge[j].flow then
          begin
            neck:=edge[j].flow;
            q:=i;
          end;
          i:=edge[j].point;
        end;
        i:=s;
        while i<>t do
        begin
          j:=cur[i];
          dec(edge[j].flow,neck);
          inc(edge[j xor ].flow,neck);
          i:=edge[j].point;
        end;
        u:=q;
      end;
      q:=-;
      i:=p[u];
      while i<>- do
      begin
        j:=edge[i].point;
        if (edge[i].flow>) and (h[u]=h[j]+) then
        begin
          q:=i;
          break;
        end;
        i:=edge[i].next;
      end;
      if q<>- then
      begin
        cur[u]:=q;
        pre[j]:=u;
        u:=j;
      end
      else begin
        dec(numh[h[u]]);
        if numh[h[u]]= then exit;
        tmp:=n;
        i:=p[u];
        while i<>- do
        begin
          j:=edge[i].point;
          if edge[i].flow> then tmp:=min(tmp,h[j]);
          i:=edge[i].next;
        end;
        h[u]:=tmp+;
        inc(numh[h[u]]);
        if u<>s then u:=pre[u];
      end;
    end;
  end; procedure tarjan(x:longint);
  var i,y:longint;
  begin
    v[x]:=true;
    f[x]:=true;
    inc(r);
    inc(d);
    st[r]:=x;
    dfn[x]:=d;
    low[x]:=d;
    i:=p[x];
    while i<>- do
    begin
      y:=edge[i].point;
      if edge[i].flow> then
      begin
        if not v[y] then
        begin
          tarjan(y);
          low[x]:=min(low[x],low[y]);
        end
        else if f[y] then
          low[x]:=min(low[x],low[y]);
      end;
      i:=edge[i].next;
    end;
    if low[x]=dfn[x] then
    begin
      inc(tot);
      while st[r+]<>x do
      begin
        y:=st[r];
        f[y]:=false;
        be[y]:=tot;
        dec(r);
      end;
    end;
  end; begin
  readln(n,m,s,t);
  len:=-;
  fillchar(p,sizeof(p),);
  for i:= to m do
  begin
    readln(x,y,z);
    add(x,y,z);
    add(y,x,);
  end;
  sap;
  for i:= to n do
    if not v[i] then
    begin
      r:=;
      d:=;
      tarjan(i);
    end;
  i:=;
  while i<=len do
  begin
    if (edge[i].flow=) then
    begin
      x:=edge[i].from;
      y:=edge[i].point;
      if be[x]<>be[y] then
      begin
        ans1[i div +]:=;
        if (be[x]=be[s]) and (be[y]=be[t]) or (be[x]=be[t]) and (be[y]=be[s]) then
          ans2[i div +]:=;
      end;
    end;
    i:=i+;
  end;
  for i:= to m do
    writeln(ans1[i],' ',ans2[i]);
end.

bzoj1797的更多相关文章

  1. 【bzoj1797】 Ahoi2009—Mincut 最小割

    http://www.lydsy.com/JudgeOnline/problem.php?id=1797 (题目链接) 题意 求一条边是否可能在一个最小割集中,以及这条边是否一定在最小割集中. Sol ...

  2. 【BZOJ1797】[AHOI2009]最小割(网络流)

    [BZOJ1797][AHOI2009]最小割(网络流) 题面 BZOJ 洛谷 题解 最小割的判定问题,这里就当做记结论吧.(源自\(lun\)的课件) 我们先跑一遍最小割,求出残量网络.然后把所有还 ...

  3. 【BZOJ-1797】Mincut 最小割 最大流 + Tarjan + 缩点

    1797: [Ahoi2009]Mincut 最小割 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1685  Solved: 724[Submit] ...

  4. bzoj1797: [Ahoi2009]Mincut 最小割

    最大流+tarjan.然后因为原来那样写如果图不连通的话就会出错,WA了很久. jcvb: 在残余网络上跑tarjan求出所有SCC,记id[u]为点u所在SCC的编号.显然有id[s]!=id[t] ...

  5. BZOJ1797:[AHOI2009]最小割(最小割)

    Description A,B两个国家正在交战,其中A国的物资运输网中有N个中转站,M条单向道路.设其中第i (1≤i≤M)条道路连接了vi,ui两个中转站,那么中转站vi可以通过该道路到达ui中转站 ...

  6. 【bzoj1797】[Ahoi2009]Mincut 最小割 网络流最小割+Tarjan

    题目描述 给定一张图,对于每一条边询问:(1)是否存在割断该边的s-t最小割 (2)是否所有s-t最小割都割断该边 输入 第一行有4个正整数,依次为N,M,s和t.第2行到第(M+1)行每行3个正 整 ...

  7. 【最小割】【Dinic】【强联通分量缩点】bzoj1797 [Ahoi2009]Mincut 最小割

    结论: 满足条件一:当一条边的起点和终点不在 残量网络的 一个强联通分量中.且满流. 满足条件二:当一条边的起点和终点分别在 S 和 T 的强联通分量中.且满流.. 网上题解很多的. #include ...

  8. [BZOJ1797][AHOI2009]最小割Mincut

    bzoj luogu sol 一条边出现在最小割集中的必要条件和充分条件. 先跑出任意一个最小割,然后在残余网络上跑出\(scc\). 一条边\((u,v)\)在最小割集中的必要条件:\(bel[u] ...

  9. BZOJ1797 [Ahoi2009]Mincut 最小割 【最小割唯一性判定】

    题目 A,B两个国家正在交战,其中A国的物资运输网中有N个中转站,M条单向道路.设其中第i (1≤i≤M)条道路连接了vi,ui两个中转站,那么中转站vi可以通过该道路到达ui中转站,如果切断这条道路 ...

随机推荐

  1. [翻译]AOP编程

    翻译文章链接http://www.codeproject.com/Articles/1080517/Aspect-Oriented-Programming-using-Interceptors-wit ...

  2. MVC异步 导入excel文件

    View页面 js文件.封装到一个js文件里面 (function ($) { //可以忽略 var defaultSettings = { url: "http://upload.zhtx ...

  3. Linux之CentOS下vsftp安装及配置相关操作

    1.安装ftps——vsftpd: #yum install vsftpd 2.指定上传下载目录配置: 如:用户名:xxx,需指定目录:/xxx/xxx #useradd -d /xxx/xxx -s ...

  4. jquery验证手机号码、邮箱格式是否正确示例代码

    本文为大家介绍下使用jquery验证邮箱.验证手机号码,具体实现思路及代码如下,感兴趣的朋友可以学习下 复制代码代码如下: //jquery验证邮箱  function checkSubmitEmai ...

  5. Oracle分析函数之LEAD和LAG

    LAG 访问结果集中当前行之前的行 LAG (value_expr [,offset] [,default])OVER ( [ partition_by_clause ] order_by_claus ...

  6. 如何实现一个malloc函数

    一.概述 1.malloc简介 函数所在头文件:<stdlib.h> 函数原型是:void *malloc (size_t n) 函数功能:在内存的动态存储区中分配一个长度为size的连续 ...

  7. JS & DOM 对象

    22:36 2013/6/4 详情参照W3C文档标准 Browser 对象(顶层对象) DOM Window DOM Navigator DOM Screen DOM History DOM Loca ...

  8. user is not mapped

    用Hibernate实现一个用户的登陆过程,当我在JSP的登陆页面输入姓名和密码,点登陆后,显示登陆失败页,在服务器里显示如下的错误信息:  org.hibernate.hql.ast.QuerySy ...

  9. 常用DOS命令参数详解

    一.DIR命令的格式: dir [D:][PATH][NAME][[/A][:attrib]][/o:[sorted][/s][/b][/l][/c[h] (1)dir /a:attrib 缺省包含所 ...

  10. c++ 类的对象与指针

    这里首先我们需区分一下指针数组和数组指针. 指针数组:int *p[4];它最终是个数组,只是这个数组存储的是4个指向int类型的指针. 数组指针:int (*P)[4];它最终是个指针,表示一个指向 ...