ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Common Board

Why WA#1?Help me please (1077)?
Posted by Saturn (HUS) 6 Jul 2004 12:17
const
        maxn=200;
        maxm=20000;
var
        a:array[1..maxn,1..maxn]of boolean;
        b:array[1..maxn,1..maxn]of boolean;
        d:array[1..maxn]of boolean;
        cx,cy:array[1..maxm]of longint;
        m,tt,sc,i,j,k,n,x,y:longint;

procedure timck(s:longint);
var p:longint;
begin
        if k=n then exit;
        d[s]:=false;
        for p:=1 to n do
        if a[s,p] and d[p] and (k<n) then
        begin
                inc(k);
                b[s,p]:=true;
                b[p,s]:=true;
                timck(p);
        end;
end;

procedure timct(s:longint);
var q:array[1..201]of longint;
    t:array[1..201]of longint;
    h:array[1..201]of longint;
    w,i,j,f,l:longint;
begin
    fillchar(d,sizeof(d),true);
    f:=1;l:=1;q[f]:=cx[s];d[cx[s]]:=false;
    t[cx[s]]:=0;
    while f<=l do
    begin
        if q[l]=cy[s] then break;
        for i:=1 to n do
        if d[i] and b[q[f],i] then
        begin
                inc(l);
                q[l]:=i;
                t[i]:=q[f];
                d[i]:=false;
                if i=cy[s] then break;
        end;
        inc(f);
    end;
    i:=q[l];
    w:=0;
    while i<>0 do
    begin
        inc(w);
        h[w]:=i;
        i:=t[i];
    end;
    write(w,' ');
    for i:=1 to w do
    write(h[i],' ');
    writeln;
end;

begin
        fillchar(a,sizeof(a),false);
        fillchar(b,sizeof(b),false);
        sc:=0;
        readln(n,m);
        for i:=1 to m do
        begin
                readln(x,y);
                if not a[x,y] then
                begin
                        a[x,y]:=true;
                        a[y,x]:=true;
                        inc(sc);
                        cx[sc]:=x;
                        cy[sc]:=y;
                end;
        end;

        fillchar(d,sizeof(d),true);
        k:=1;
        timck(1);
        writeln(sc-n+1);

        if sc-n+1<>0 then
        begin
                for i:=1 to sc do
                if not b[cx[i],cy[i]] then timct(i);
        end;
end.
Re: Why WA#1?Help me please (1077)?
Posted by Saturn (HUS) 6 Jul 2004 17:19
Sorry I get AC now. I didn't read the problem carefully