首先要保证每一封信都能找到和它匹配的信封,即满足完美匹配
所以如果不满足完美匹配直接输出none
然后我们知道了每封信对应的信封other[i],和每个信封对应的信link[i]
枚举删边,如果我们不让信i与它的匹配信封other[i]相连即不让它两个匹配
如果此时i无法匹配说明i只能与other[i]匹配,输出i和other[i]
注意对每一个信判断完后后对相应数组的复原
var
n,a,b,ans,t :longint;
i :longint;
map :array[0..110,0..110] of boolean;
vis :array[0..110] of boolean;
link,other :array[0..110] of longint;
flag :boolean;
function find(x:longint):boolean;
var
p:longint;
begin
for p:=1 to n do
begin
if not vis[p] and not map[x,p] then
begin
vis[p]:=true;
if (link[p]=0) or (find(link[p])) then
begin
link[p]:=x;
other[x]:=p;
exit(true);
end;
end;
end;
exit(false);
end;
begin
read(n);
read(a,b);
while (a<>0) and (b<>0) do
begin
map[a,b]:=true;
read(a,b);
end;
for i:=1 to n do
begin
fillchar(vis,sizeof(vis),false);
if find(i) then inc(ans);
end;
//
if (ans<>n) then
begin
writeln('none');exit;
end;
//
for i:=1 to n do
begin
map[i,other[i]]:=true;
t:=other[i];
link[other[i]]:=0;
other[i]:=0;
fillchar(vis,sizeof(vis),false);
if not find(i) then
begin
writeln(i,' ',t);flag:=true;
end;
map[i,t]:=false;
other[i]:=t;link[t]:=i;
end;
//
if not flag then writeln('none');
end.
——by Eirlys
转载请注明出处=w=