• 1339 / 1163: [Baltic2008]Mafia


    1163: [Baltic2008]Mafia

    Time Limit: 10 Sec  Memory Limit: 162 MB
    Submit: 96  Solved: 60
    [Submit][Status][Discuss]

    Description

    匪徒准备从一个车站转移毒品到另一个车站,警方准备进行布控. 对于每个车站进行布控都需要一定的代价,现在警方希望使用最小的代价控制一些车站,使得去掉这些车站后,匪徒无法从原定的初始点到达目标点

    Input

    第一行输入N,M代表车站的总个数,及有多少条双向边连接它们. 2<=n<=200 , 1 <=m<=20000. 第二行给出两个数a,b,代表匪徒的出发点及目标点.1<=a,b<=N,a<>b. 再下来有N行,给出对第i个车站进行布控所需要的Money,其不超过10 000 000 再下来M行,用于描述图的结构.

    Output

    最少需要多少Money

    Sample Input

    5 6
    5 3
    2
    4
    8
    3
    10
    1 5
    1 2
    2 4
    4 5
    2 3
    3 4

    Sample Output

    5

    HINT

     

    Source

    题解:一个呵呵呵的最小割,将每个题目中的车站拆分成两个点,然后连接上一条边权为该站点费用的边,然后别的题目中所述的边直接连双向边,注意别弄乱了就是了

     1 /**************************************************************
     2     Problem: 1163
     3     User: HansBug
     4     Language: Pascal
     5     Result: Accepted
     6     Time:156 ms
     7     Memory:2652 kb
     8 ****************************************************************/
     9  
    10 type
    11     point=^node;
    12     node=record
    13                g,w:longint;
    14                next,anti:point;
    15     end;
    16 var
    17    i,j,k,l,m,n,s,t,ans:longint;
    18    a:array[0..5000] of point;
    19    d,dv:array[0..5000] of longint;
    20 function min(x,y:longint):longint;
    21          begin
    22               if x<y then min:=x else min:=y;
    23          end;
    24 procedure add(x,y,z:longint);
    25           var p:point;
    26           begin
    27                new(p);p^.g:=y;p^.w:=z;p^.next:=a[x];a[x]:=p;
    28                new(p);p^.g:=x;p^.w:=0;p^.next:=a[y];a[y]:=p;
    29                a[x]^.anti:=a[y];a[y]^.anti:=a[x];
    30           end;
    31 function dfs(x,flow:longint):longint;
    32          var p:point;k:longint;
    33          begin
    34               if x=t then exit(flow);
    35               dfs:=0;p:=a[x];
    36               while p<>nil do
    37                     begin
    38                          if (p^.w<>0) and (d[x]=(d[p^.g]+1)) then
    39                             begin
    40                                  k:=dfs(p^.g,min(flow-dfs,p^.w));
    41                                  if p^.w<>maxlongint then dec(p^.w,k);
    42                                  if p^.anti^.w<>maxlongint then inc(p^.anti^.w,k);
    43                                  inc(dfs,k);if dfs=flow then exit;
    44                             end;
    45                          p:=p^.next;
    46                     end;
    47               if d[s]=n then exit;
    48               dec(dv[d[x]]);
    49               if dv[d[x]]=0 then d[s]:=n;
    50               inc(d[x]);inc(dv[d[x]]);
    51          end;
    52 begin
    53      readln(n,m);
    54      for i:=1 to n*2 do a[i]:=nil;
    55      readln(s,t);s:=s*2-1;t:=t*2;
    56      for i:=1 to n do
    57          begin
    58               readln(j);
    59               add(i*2-1,i*2,j);
    60          end;
    61      for i:=1 to m do
    62          begin
    63               readln(j,k);
    64               add(j*2,k*2-1,maxlongint);
    65               add(k*2,j*2-1,maxlongint);
    66          end;
    67      fillchar(dv,sizeof(dv),0);
    68      fillchar(d,sizeof(d),0);
    69      ans:=0;n:=n*2;
    70      while d[s]<n do inc(ans,dfs(s,maxlongint));
    71      writeln(ans);
    72      readln;
    73 end.
     
     
  • 相关阅读:
    windows下编译php7图形库php_ui.dll
    php 图形用户界面GUI 开发
    使用PHPStorm 配置自定义的Apache与PHP环境
    公用代码实现两个表的拼接(部分代码)
    WCF学习心得--客户端获取服务端自定义类数据
    动态规划入门——Eddy's research II
    linux route命令学习
    软件度量都该度个啥?(5)——被吹得最多的六西格玛
    VSS的运用小内容(针对于vs2008版本)(小的问题都是,仅供参考--只针对于菜鸟级的)
    cocos2d-x学习日志(13) --A星寻路算法demo
  • 原文地址:https://www.cnblogs.com/HansBug/p/4491503.html
Copyright © 2020-2023  润新知