123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- {$M 6400000}
- program ural1099_5_5;
- const maxn=300;
- randtime=5;
- tttime=5;
- var n,ans:longint;
- p,q,my,ansy:array[1..maxn]of longint;
- map:array[1..maxn,1..maxn]of boolean;
- u:array[1..maxn]of boolean;
- procedure swap(var x,y:longint);
- var t:longint;
- begin
- t:=x;x:=y;y:=t;
- end;
- procedure inputint;
- var a,b:longint;
- begin
- readln(n);
- while not(eof) do
- begin
- readln(a,b);
- map[a,b]:=true;
- map[b,a]:=true;
- end;
- end;
- function aug(x:longint):boolean;
- var i:longint;
- begin
- u[x]:=true;
- for i:=1 to n do
- if not(u[q[i]]) then
- if map[x,q[i]] then
- begin
- u[q[i]]:=true;
- if (my[q[i]]=0)or(aug(my[q[i]])) then
- begin
- my[q[i]]:=x;
- my[x]:=q[i];
- aug:=true;
- exit;
- end;
- end;
- aug:=false;
- end;
- procedure updata(tmp:longint);
- var i:longint;
- begin
- ans:=tmp;
- for i:=1 to n do ansy[i]:=my[i];
- end;
- procedure workans;
- var i,tmp,j,k,ttt:longint;
- begin
- fillchar(my,sizeof(my),0);
- tmp:=0;
- for i:=1 to n do
- if my[p[i]]=0 then
- for ttt:=1 to tttime do
- begin
- fillchar(u,sizeof(u),0);
- if aug(p[i]) then begin inc(tmp);break end
- else
- for j:=1 to n do
- begin
- k:=j+random(n-j+1);
- swap(q[j],q[k]);
- end;
- end;
- if tmp>ans then updata(tmp);
- end;
- procedure work;
- var i,j,time:longint;
- begin
- for i:=1 to n do
- begin
- p[i]:=i;
- q[i]:=i;
- end;
- for time:=1 to randtime do
- begin
- for i:=1 to n do
- begin
- j:=i+random(n-i+1);
- swap(q[i],q[j]);
- j:=i+random(n-i+1);
- swap(p[i],p[j]);
- end;
- workans;
- end;
- end;
- procedure outputint;
- var i:longint;
- begin
- writeln(ans*2);
- for i:=1 to n do
- if ansy[i]>i then writeln(i,' ',ansy[i]);
- end;
- begin
- randomize;
- inputint;
- work;
- outputint;
- end.
|