PersonalCorpus 版 (精华区)

154589 07:09:58 5 Mar 2002
Bozhang,HIT,P.R.China 1080 Pascal Accepted 0.02 sec 61K


var
    dl:array[1..98,1..98] of boolean;
    color:array[1..98] of byte;
    check:array[1..98] of boolean;
    ok,flag:boolean;
    i,j,k,n:integer;
begin
    readln(n);fillchar(dl,sizeof(dl),0);
    for i:=1 to n do begin
        read(j);
        while j<>0 do begin
            dl[i,j]:=true; dl[j,i]:=true;
            read(j);
        end;
        readln
    end;
    fillchar(color,sizeof(color),2);
    fillchar(check,sizeof(check),0);
    color[1]:=0; k:=1; flag:=true; ok:=true;
    while flag do begin
        for i:=1 to n do if i<>k then if dl[i,k] then begin
            if color[i]=color[k] then begin flag:=false; ok:=false; break end;
            color[i]:=1-color[k];
            check[i]:=true; dl[i,k]:=false; dl[k,i]:=false;
        end;
        if not flag then break;
        check[k]:=false;
        for k:=1 to n do if check[k] then break;
        if k>n then begin
            for k:=1 to n do if color[k]=2 then break;
            if k>n then begin
                ok:=true;
                break;
            end else color[k]:=0;
        end;
    end;
    if ok then begin
        for i:=1 to n do write(color[i]);writeln;
    end else writeln(-1);
end.
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.095毫秒