1 /**************************************************************
2 Problem: 1741
3 User: HansBug
4 Language: Pascal
5 Result: Accepted
6 Time:20 ms
7 Memory:1036 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..20000] of point;
19 d,dv:array[0..20000] 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 p:=a[x];dfs:=0;
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);
44 if dfs=flow then exit;
45 end;
46 p:=p^.next;
47 end;
48 if d[s]=n then exit;
49 dec(dv[d[x]]);
50 if dv[d[x]]=0 then d[s]:=n;
51 inc(d[x]);inc(dv[d[x]]);
52 end;
53 begin
54 readln(n,m);
55 for i:=0 to n*2+m+1 do a[i]:=nil;
56 for i:=1 to n do
57 begin
58 add(0,i,1);add(n+m+i,n*2+m+1,1);
59 end;
60 for i:=1 to m do
61 begin
62 readln(j,k);
63 add(j,n+i,1);add(n+i,n+m+k,1);
64 end;
65 s:=0;t:=n*2+m+1;
66 n:=n*2+m+2;
67 fillchar(d,sizeof(d),0);
68 fillchar(dv,sizeof(dv),0);
69 dv[0]:=n;ans:=0;
70 while d[s]<n do inc(ans,dfs(s,maxlongint));
71 writeln(ans);
72 readln;
73 end.
1 /**************************************************************
2 Problem: 1741
3 User: HansBug
4 Language: Pascal
5 Result: Accepted
6 Time:44 ms
7 Memory:1460 kb
8 ****************************************************************/
9
10 type
11 point=^node;
12 node=record
13 g:longint;
14 next:point;
15 end;
16 var
17 i,j,k,l,m,n,ans:longint;
18 a:array[0..100000] of point;
19 c,f:array[0..100000] of longint;
20 procedure add(x,y:longint);
21 var p:point;
22 begin
23 new(p);p^.g:=y;
24 p^.next:=a[x];a[x]:=p;
25 end;
26 function check(x:longint):boolean;
27 var p:point;
28 begin
29 p:=a[x];
30 while p<>nil do
31 begin
32 if f[p^.g]<>i then
33 begin
34 f[p^.g]:=i;
35 if c[p^.g]=0 then
36 begin
37 c[p^.g]:=x;
38 exit(true);
39 end
40 else if check(c[p^.g]) then
41 begin
42 c[p^.g]:=x;
43 exit(true);
44 end;
45 end;
46 p:=p^.next;
47 end;
48 exit(false);
49 end;
50 begin
51 readln(n,m);
52 for i:=1 to n do a[i]:=nil;
53 for i:=1 to m do
54 begin
55 readln(j,k);
56 add(j,k);
57 end;
58 ans:=0;
59 fillchar(c,sizeof(c),0);
60 fillchar(f,sizeof(f),0);
61 for i:=1 to n do if check(i) then inc(ans);
62 writeln(ans);;
63 readln;
64 end.