第一问不谈,

第二问首先我们要找出哪些是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. jquery动态插入行

    这是一个利用jquery动态插入输入内容的代码. html代码: <div title="分表2" class="ui-edit" style=" ...

  2. 392. Is Subsequence

    392. Is Subsequence 水题,先是判断长度,长度t比s小,返回false,然后从左到右扫描t,然后同时扫描s,如果相同,s的index就往后拉一个,如果s的index等于s长度,返回t ...

  3. mysql数据库之索引和分析索引

    分析查询语句是否用到了索引 explain sql语句\G //根据返回的信息,我们可知,该sql语句是否使用索引,从多少记录中取出,可以看到排序的方式. 主要是看 key 实际用到的索引 rows ...

  4. 相册弹窗(基于zepto.js)

    //放大图片 $(page).on('click','.popupImage img',function () { var that = $(this); that.popupImage({ this ...

  5. 从Python传递JSON到JavaScript

    OS: Windows 8.1 with update 关键字:Python 3.4,HTML5,JSON,JavaScript 1.LocalServer.py,启动server,打开网页,传递JS ...

  6. Stop a hung service 关闭一个无响应的windows 服务

    If you ever have trouble with a service being stuck in a 'starting' or 'stopping' state, you can run ...

  7. C语言之指针

    以32为系统为例. 1.指针与地址指针是一种变量,保存了所指向对象的地址.1.1 定义int i = 10;int *p = &i; //定义了一个指针p,它指向一个int型的变量&是 ...

  8. 【java】Servlet 工程 web.xml 中的 servlet 和 servlet-mapping 标签

    摘录某个工程的 web.xml 文件片段: 访问顺序为1—>2—>3—>4,其中2和3的值必须相同. url-pattern 标签中的值是要在浏览器地址栏中输入的 url,可以自己命 ...

  9. C# - implicit, explicit

    如果类型直接没有继承关系,也没有共享接口,想在这两个类型之间进行转换,就必须重载转换运算符. 此时需要关键字implicit和explicit. 下面定义了类型ConvClass1和ConvClass ...

  10. .net 添加不同项目框架引用出现的问题

    问题描述: winform项目添加web项目时出现问题,winform项目添加web项目类时,老是报找不到这个类的命名空间 最后才知道两个项目所建的框架不一样,一个是.net framework 4, ...