题目大意:
有N 个局部联通的图。
Harry 和Sally 轮流从图中删边,删去一条边后,不与根节点相连的部分将被移走。Sally 为先手。
图是通过从基础树中加一些边得到的。
所有形成的环保证不共用边,且只与基础树有一个公共点。
谁无路可走谁输。
有N 个局部联通的图。
Harry 和Sally 轮流从图中删边,删去一条边后,不与根节点相连的部分将被移走。Sally 为先手。
图是通过从基础树中加一些边得到的。
所有形成的环保证不共用边,且只与基础树有一个公共点。
谁无路可走谁输。
【输入】
多组数据
每组数据第一行m和k表示m个节点,k条边,1为根节点
接下来k行描述边
【输出】
对于每组数据输出谁必胜
2009年贾志豪的论文有讲
program poj3710;
var
a,b,tot,ans,n,m,k,i,j:longint;
yes:array [0..101] of boolean;
round,high,sg,father,root:array [0..101] of longint;
point,next:array [0..1001] of longint;
procedure connect (a,b:longint);
begin
inc(tot);
point[tot]:=b;
next[tot]:=root[a];
root[a]:=tot;
end;
procedure dfs (now,h:longint);
var
i:longint;
begin
yes[now]:=true;
high[now]:=h;
i:=root[now];
while i<>0 do
begin
if (point[i]<>father[now])and(point[i]<>now) then
if not yes[point[i]] then
begin
father[point[i]]:=now;
dfs(point[i],h+1);
case round[now] of
0:sg[now]:=sg[now] xor (sg[point[i]]+1);
1:;
2:sg[now]:=sg[now] xor 1;
end;
round[now]:=0;
end
else
if high[point[i]]<high[now] then
if (high[now]-high[point[i]]) and 1 = 1 then round[point[i]]:=1
else round[point[i]]:=2;
if point[i]=father[now] then father[now]:=0;
i:=next[i];
end;
end;
begin
while not seekeof do
begin
ans:=0;
read(n);
while n>0 do
begin
dec(n);
read(m,k);
fillchar(father,sizeof(father),0);
fillchar(round,sizeof(round),0);
fillchar(yes,sizeof(yes),false);
fillchar(root,sizeof(root),0);
fillchar(sg,sizeof(sg),0);
tot:=0;
for i:=1 to k do
begin
read(a,b);
connect(a,b);
connect(b,a);
end;
dfs(1,1);
ans:=ans xor sg[1];
end;
if ans=0 then writeln('Harry')
else writeln('Sally');
end;
end.