最小可相交路径覆盖
先预处理可到达的点然后转化为最小不相交路径覆盖
1 type node=record 2 point,next:longint; 3 end; 4 5 var edge:array[0..101000] of node; 6 p,cx,cy:array[0..200] of longint; 7 v:array[0..200] of boolean; 8 a,b:array[0..200,0..200] of boolean; 9 j,len,n,m,x,y,ans,i:longint; 10 11 procedure add(x,y:longint); 12 begin 13 inc(len); 14 edge[len].point:=y; 15 edge[len].next:=p[x]; 16 p[x]:=len; 17 end; 18 19 function find(x:longint):longint; 20 var i,y:longint; 21 begin 22 i:=p[x]; 23 while i<>-1 do 24 begin 25 y:=edge[i].point; 26 if not v[y] then 27 begin 28 v[y]:=true; 29 if (cy[y]=-1) or (find(cy[y])>0) then 30 begin 31 cx[x]:=y; 32 cy[y]:=x; 33 exit(1); 34 end; 35 end; 36 i:=edge[i].next; 37 end; 38 exit(0); 39 end; 40 41 procedure dfs(x:longint); 42 var i:longint; 43 begin 44 v[x]:=true; 45 for i:=1 to n do 46 if a[x,i] and not v[i] then dfs(i); 47 end; 48 49 begin 50 readln(n,m); 51 fillchar(p,sizeof(p),255); 52 for i:=1 to m do 53 begin 54 readln(x,y); 55 a[x,y]:=true; 56 end; 57 for i:=1 to n do 58 begin 59 fillchar(v,sizeof(v),false); 60 dfs(i); 61 for j:=1 to n do 62 if v[j] and (i<>j) then 63 add(i,j); 64 end; 65 fillchar(cx,sizeof(cx),255); 66 fillchar(cy,sizeof(cy),255); 67 for i:=1 to n do 68 if cx[i]=-1 then 69 begin 70 fillchar(v,sizeof(v),false); 71 ans:=ans+find(i); 72 end; 73 writeln(n-ans); 74 end.