# BZOJ1934: [Shoi2007]Vote 善意的投票

## 1934: [Shoi2007]Vote 善意的投票

Time Limit: 1 Sec  Memory Limit: 64 MB
Submit: 1076  Solved: 660
[Submit][Status]

3 3
1 0 0
1 2
1 3
3 2

1

## Source

(1) 冲突数不大于 n:

(2) “同意”集合和“否定”集合之间的边全部是朋友关系
(3) 冲突是同意与不同意之间的割

  1 const inf=maxlongint;
2 type node=record
3      from,go,next,v:longint;
4      end;
5 var  tot,i,j,n,m,maxflow,l,r,s,t,x,y:longint;
7      e:array[0..200000] of node;
8      function min(x,y:longint):longint;
9       begin
10       if x<y then exit(x) else exit(y);
11       end;
12 procedure ins(x,y,z:longint);
13  begin
14  inc(tot);
16  end;
17 procedure insert(x,y,z:longint);
18  begin
19  ins(x,y,z);ins(y,x,0);
20  end;
21 function bfs:boolean;
22  var i,x,y:longint;
23  begin
24  fillchar(h,sizeof(h),0);
25  l:=0;r:=1;q[1]:=s;h[s]:=1;
26  while l<r do
27   begin
28   inc(l);
29   x:=q[l];
31   while i<>0 do
32    begin
33    y:=e[i].go;
34    if (e[i].v<>0) and (h[y]=0) then
35     begin
36      h[y]:=h[x]+1;
37      inc(r);q[r]:=y;
38     end;
39    i:=e[i].next;
40    end;
41   end;
42  exit (h[t]<>0);
43  end;
44 function dfs(x,f:longint):longint;
45  var i,y,used,tmp:longint;
46  begin
47  if x=t then exit(f);
48  used:=0;
49  i:=cur[x];
50  while i<>0 do
51   begin
52   y:=e[i].go;
53   if (h[y]=h[x]+1) and (e[i].v<>0) then
54    begin
55    tmp:=dfs(y,min(e[i].v,f-used));
56    dec(e[i].v,tmp);if e[i].v<>0 then cur[x]:=i;
57    inc(e[i xor 1].v,tmp);
58    inc(used,tmp);
59    if used=f then exit(f);
60    end;
61   i:=e[i].next;
62   end;
63  if used=0 then h[x]:=-1;
64  exit(used);
65  end;
66 procedure dinic;
67  begin
68  while bfs do
69   begin
70   for i:=s to t do cur[i]:=head[i];
71   inc(maxflow,dfs(s,inf));
72   end;
73  end;
74 procedure init;
75  begin
76  tot:=1;
78  s:=0;t:=n+1;
79  for i:=1 to n do
80   begin
82   if x=0 then insert(s,i,1)
83   else insert(i,t,1);
84   end;
86  for i:=1 to m do begin readln(x,y);insert(x,y,1);insert(y,x,1);end;
87  end;
88 procedure main;
89  begin
90  maxflow:=0;
91  dinic;
92  writeln(maxflow);
93  end;
94 begin
95  assign(input,'input.txt');assign(output,'output.txt');
96  reset(input);rewrite(output);
97  init;
98  main;
99  close(input);close(output);
100 end.       
View Code

posted @ 2014-08-12 19:56  ZYF-ZYF  Views(115)  Comments(0Edit  收藏