poj3710

题目大意:
有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.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值