第一问不谈,

第二问首先我们要找出哪些是s到t的最短路上的边

由于是无向图,首先正反两遍最短路,求出是s到任意点的距离,任意点到t的距离(即t到任意点的距离);

然后穷举每条边判断是否在最短路上用d[x,y]表示x到y的最短路

则要满足d[s,x]+w(x,y)+d[y,t]=d[s,t],

然后以代价为流量建图跑最小割即可

注意每条无向边边要当做两条有向边考虑;

 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.

bzoj1266的更多相关文章

  1. BZOJ1266 AHOI2006上学路线(最短路+最小割)

    求出最短路后找出可能在最短路上的边,显然割完边后我们需要让图中这样的边无法构成1到n的路径,最小割即可,非常板子. #include<iostream> #include<cstdi ...

  2. BZOJ1266 [AHOI2006]上学路线route Floyd 最小割 SAP

    欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ1266 题意概括 一个无向图,第一问:从1~n的最短路. 第二问,删除价值总和最小的边,使得1~n的 ...

  3. 【BZOJ1266】[AHOI2006]上学路线route Floyd+最小割

    [BZOJ1266][AHOI2006]上学路线route Description 可可和卡卡家住合肥市的东郊,每天上学他们都要转车多次才能到达市区西端的学校.直到有一天他们两人参加了学校的信息学奥林 ...

  4. bzoj1266最短路+最小割

    本来写了spfa wa了 看到网上有人写Floyd过了 表示不开心 ̄へ ̄ 改成Floyd试试... 还是wa ヾ(。`Д´。)原来是建图错了(样例怎么过的) 结果T了 于是把Floyd改回spfa 还 ...

  5. bzoj1266: [AHOI2006]上学路线route

    最短路+最小割 首先如何使最短路变长?就是要每一条最短路都割一条边. 我们求出每个点到点1和点n的距离,就可以知道哪些边在最短路上(一开始没有想到求到0和n的距离,想用floyd,但是n=500,怕超 ...

  6. BZOJ1266 [AHOI2006]上学路线

    Description 可可和卡卡家住合肥市的东郊,每天上学他们都要转车多次才能到达市区西端的学校.直到有一天他们两人参加了学校的信息学奥林匹克竞赛小组才发现每天上学的乘车路线不一定是最优的. 可可: ...

  7. 【最短路】【spfa】【最小割】【Dinic】bzoj1266 [AHOI2006]上学路线route

    原问题等价于断掉一些边,让原来所有的最短路全都无法联通S和T. 先求最短路,然后把在最短路上的边(dis[u[i]]+w[i]==dis[v[i]])加入新图里,跑最小割.显然. 注意是无向图. #i ...

  8. bzoj1266 [AHOI2006]上学路线route floyd建出最短路图+最小割

    1266: [AHOI2006]上学路线route Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 2490  Solved: 898[Submit][S ...

  9. bzoj1266 [AHOI2006]上学路线route floyd+最小割

    1266: [AHOI2006]上学路线route Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 2490  Solved: 898[Submit][S ...

随机推荐

  1. Java 7 新的 try-with-resources 语句,自动资源释放

    Java 7 的编译器和运行环境支持新的 try-with-resources 语句,称为 ARM 块(Automatic Resource Management) ,自动资源管理. 新的语句支持包括 ...

  2. POJ1384完全背包问题

    题目大意:给你一个储蓄罐空的,和满的重量,然后给出各种硬币的价值和对应的重量,要你估计出储蓄罐里面硬币价值和最小为多少,注意要保证重量和恰好为给出满的重量解题思路:完全背包问题,只是求最小值,注意初始 ...

  3. PHP中使用cURL

    1.cURL介绍 cURL 是一个利用URL语法规定来传输文件和数据的工具,支持很多协议,如HTTP.FTP.TELNET等.最爽的是,PHP也支持 cURL 库.本文将介绍 cURL 的一些高级特性 ...

  4. thinkphp表单上传文件并将文件路径保存到数据库中

    上传单个文件,此文以上传图片为例,上传效果如图所示 创建数据库upload_img,用于保存上传路径 CREATE TABLE `seminar_upload_img` (  `id` int(11) ...

  5. NpoiUtil

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...

  6. php文本操作方法集合

    fgets和fputs.fread和fwrite.fscanf和fprintf 字符串读写函数fgets和fputs  一.读字符串函数fgets函数的功能是从指定的文件中读一个字符串到字符数组中,函 ...

  7. Dreamweaver 添加 cakephp ctp后缀名

    Dreamweaver 默认是不支持ctp文件高亮的,即使用Dreamweaver打开ctp文件,也只能像记事本一样编辑 但是我们可以通过修改两个文件,来添加Dreamweaver对ctp文件的扩展支 ...

  8. LNMP1.2一键安装教程

    系统需求: CentOS/RHEL/Fedora/Debian/Ubuntu/Raspbian Linux系统 需要2GB以上硬盘剩余空间 128M以上内存,Xen的需要有SWAP,OpenVZ的另外 ...

  9. Html学习_style属性应用

    用style属性改变字体大小.颜色.字体.背景颜色和对齐方式 <!DOCTYPE html> <html> <head> <title>Putting ...

  10. 图论(四)------非负权有向图的单源最短路径问题,Dijkstra算法

    Dijkstra算法解决了有向图G=(V,E)上带权的单源最短路径问题,但要求所有边的权值非负. Dijkstra算法是贪婪算法的一个很好的例子.设置一顶点集合S,从源点s到集合中的顶点的最终最短路径 ...