第一问不谈,

第二问首先我们要找出哪些是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. OC3_MyRect

    // // MyRect.h // OC3_MyRect // // Created by zhangxueming on 15/6/9. // Copyright (c) 2015年 zhangxu ...

  2. post 提交数据

    1 默认:application/x-www-form-urlencoded 在网页表单中可设置 enctype的值,如果不设,默认是 application/x-www-form-urlencode ...

  3. android开发之GenyMotion与intelliJ的配置

    (注意:这是在你的电脑上安装了intelliJ和安卓SDK后才进行的工作,如果没有intelliJ和安卓SDK,请先安装以上两样东西) 号称史上最快乐的模拟器GenyMotion,试一下. 第一步:下 ...

  4. OpenJudge 2980 大整数乘法

    链接地址:http://bailian.openjudge.cn/practice/2980/ 题目: 总时间限制: 1000ms 内存限制: 65536kB 描述 求两个不超过200位的非负整数的积 ...

  5. MySQL二进制文件规范安装

    演示环境介绍 操作系统:CentOS 6.7  (64位) 二进制包:mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz MySQL 下载地址:http://dev.m ...

  6. 我爱工程化 之 gulp 使用(二)

    上一篇  介绍了gulp的安装.环境等配置.基本使用,那么现在,我们快走进 速8,深入了解吧...... 一.各种安装.环境配置.插件安装(参考上一篇文章) 二.项目基本目录结构 三.编写 gulpf ...

  7. vs快捷键及常用设置(vs2012版)

    vs快捷键: 1.ctrl+f F是Find的简写,意为查找.在vs工具中按此快捷键,可以查看相关的关键词.比如查找哪些页面引用了某个类等.再配合查找范围(整个解决方案.当前项目.当前文档等),可以快 ...

  8. javascript函数基础

    Function类型 由于函数是对象,因此函数名实际上是一个指向函数对象的指针,不会与函数绑定 所以没有重载这个概念!!!!!!!!!!!!!!!!!!!!!!!!!! function sum1() ...

  9. python log 层次结构

    文件结构 - run.py - b -- __init__.py run.py import logging import b log = logging.getLogger("" ...

  10. ubuntu10.04搭建嵌入式开发环境

    改源 配置vim set number set autoindent set smartindent set tabstop=4 set incsearch 安装g++ 配置samba 1.先安装程序 ...