您的位置:首页 > 其它

usaco 月赛 2005 january watchcow

2013-11-20 14:24 423 查看
2013-09-18 08:13

//By BLADEVIL
var
n, m                :longint;
pre, other          :array[0..50010] of longint;
last                :array[0..10010] of longint;
flag                :array[0..50010] of boolean;
tot                 :longint;
ans                 :array[0..10010] of longint;
i                   :longint;
l                   :longint;

procedure connect(x,y:longint);
begin
inc(l);
pre[l]:=last[x];
last[x]:=l;
other[l]:=y;
end;

procedure init;
var
i                   :longint;
x, y                :longint;
begin
read(n,m);
for i:=1 to m do
begin
read(x,y);
connect(x,y);
connect(y,x);
end;
end;

procedure dfs(x:longint);
var
p, q                :longint;
begin
q:=last[x];
while q<>0 do
begin
p:=other[q];
if not flag[q] then
begin
flag[q]:=true;
dfs(p);
end;
q:=pre[q];
end;
inc(tot);
ans[tot]:=x;
end;

begin
assign(input,'watch.in'); reset(input);
assign(output,'watch.out'); rewrite(output);
init;
dfs(1);
for i:=tot downto 1 do writeln(ans[i]);
close(input); close(output);
end.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: