usaco 2000 contest 滑雪

2013-09-11 10:22

【题目大意】给定N个点的高度和M条相连的路线(单向),从最高点向下走,

到无法走时为一条路径,求不同的路径数,(一节点不同就叫不同)

【输入样例】

4 5   (N,M)

500 400 300 200  (高度)

1 2                (边)

2 3

3 4

1 4

2 4

【输出样例】

3

//By BLADEVIL
var
    n, m                    :longint;
    pre, other              :array[0..5100] of longint;
    last                    :array[0..300] of longint;
    h                       :array[0..300] of longint;
    max                     :longint;
    vis                     :array[0..300] of boolean;
    l                       :longint;
    ans                     :longint;

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

procedure init;
var
    i, x, y, z              :longint;
begin
assign(input,'ski.in'); reset(input);
assign(output,'ski.out'); rewrite(output);
    read(n,m);
    max:=0; l:=1;
    for i:=1 to n do
    begin
        read(h[i]);
        if h[i]>h[max] then max:=i;
    end;
    for i:=1 to m do
    begin
        read(x,y);
        connect(x,y);
    end;
end;

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

end;


begin
    init;
    dfs(max);
    writeln(ans);
close(input); close(output);
end.

 

posted on 2013-11-20 14:20  BLADEVIL  阅读(264)  评论(0编辑  收藏  举报