妈蛋状态都被狗吃了,已经开始不自觉对着电脑发呆……被几道二分图的题亮瞎了双眼(这么弱可是gdkoi只剩一个月gdoi只剩100+天……!!)
二分图,但是判断两个合集中的某两个点是不是只能连在一起。那么我们就在跑一边最大匹配后直接用是否可以增广来判断。如果可以增广那么这两个点是有其他方式连在一起的,否则这两个点就必须连在一起。具体做法是先去掉这两个点的边,不过那么match数组也要跟着改一下。
var map:array[0..200,0..200]of boolean; matchx,matchy:array[0..200]of longint; chose:array[0..200]of boolean; n:longint; function dfs(x:longint):boolean; var i:longint; begin for i:=1 to n do if map[x,i] and chose[i] then begin chose[i]:=false; if (matchx[i]=0) or dfs(matchx[i]) then begin matchx[i]:=x; matchy[x]:=i; exit(true); end; end; exit(false); end; procedure into; var j,k:longint; begin readln(n); fillchar(map,sizeof(map),true); while true do begin readln(j,k); if j=0 then break; map[j,k]:=false; end; end; function work:boolean; var ans,i,j:longint; flag:boolean; begin for i:=1 to n do begin fillchar(chose,sizeof(chose),true); if not dfs(i) then exit(false); end; flag:=false; for i:=1 to n do begin fillchar(chose,sizeof(chose),true); j:=matchy[i]; map[i,j]:=false; matchx[j]:=0; matchy[i]:=0; if not dfs(i) then begin writeln(i,' ',j); matchx[j]:=i; matchy[i]:=j; flag:=true; end; map[i,j]:=true; end; exit(flag); end; begin into; if not work then writeln('none'); readln; end.