比赛 20110412pm 评测结果 AAAWWWWTWWWWWWWWW
题目名称 牛棚的灯 最终得分 17
用户昵称 ybh 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2011-04-12 17:25:48
显示代码纯文本
program lights;
const
  oo=10000000;
var
  q:array[0..oo] of longint;
  map:array[0..40] of longint;
  n,m,i,h,t,r1,r2:longint;
  step:array[0..oo] of longint;
  tt:longint;

begin
  assign(input,'lights.in');
  reset(input);
  assign(output,'lights.out');
  rewrite(output);

  readln(n,m);
  for i:=1 to n do
    map[i]:=1 shl (i-1);
  for i:=1 to m do
  begin
    readln(r1,r2);
    map[r1]:=map[r1]+(1 shl (r2-1));
    map[r2]:=map[r2]+(1 shl (r1-1));
  end;

  h:=0;
  t:=1;
  q[1]:=0;
  step[1]:=0;
  tt:=(1 shl n)-1;
  while h<>t do
  begin
    h:=h+1;
    if h>oo then h:=0;
    for i:=1 to n do
    begin
      t:=t+1;
      if t>oo then t:=0;
      q[t]:=q[h] xor map[i];
      step[t]:=step[h]+1;
      if q[t]=tt then
      begin
        writeln(step[t]);
        close(input);
        close(output);
        halt;
      end;
    end;
  end;

  close(input);
  close(output);
end.