Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Project2;
- {$APPTYPE CONSOLE}
- uses
- SysUtils;
- var color,q:array[1..100] of integer;
- head,tail,i,n,x,v:integer;
- a:array[1..100,1..100] of boolean;
- f:boolean;
- Procedure add(x:integer);
- begin
- inc(tail);
- q[tail]:=x;
- end;
- function poll:integer;
- begin
- poll:=q[head];
- inc(head);
- end;
- function empty:boolean;
- begin
- if head>tail then empty:=true
- else empty:=false;
- end;
- begin
- readln(n);
- f:=true;
- head:=1;
- tail:=0;
- for i:=1 to n do
- begin
- while true do
- begin
- read(X);
- if x=0 then break;
- a[x,i]:=true;
- //a[i,x]:=true;
- end;
- end;
- for i:=1 to n do color[i]:=-1;
- color[1]:=0;
- add(1);
- while not empty do
- begin
- v:=poll;
- //writeln(color[v]);
- //writeln(v);
- //writeln(head,' ',tail);
- for i:=1 to n do
- if a[v,i] then if color[i]=color[v] then f:=false
- else begin
- color[i]:=(color[v]+1) mod 2;
- add(i);
- end;
- end;
- if f then for i:=1 to n do write(color[i])
- else write(-1);
- readln(n);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement