Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.12 KB | None | 0 0
  1. program Project2;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   SysUtils;
  7. var color,q:array[1..100] of integer;
  8.     head,tail,i,n,x,v:integer;
  9.     a:array[1..100,1..100] of boolean;
  10.     f:boolean;
  11. Procedure add(x:integer);
  12. begin
  13. inc(tail);
  14. q[tail]:=x;
  15. end;
  16.  
  17. function poll:integer;
  18. begin
  19. poll:=q[head];
  20. inc(head);
  21. end;
  22.  
  23. function empty:boolean;
  24. begin
  25. if head>tail then empty:=true
  26.              else empty:=false;
  27. end;
  28.  
  29. begin
  30. readln(n);
  31. f:=true;
  32. head:=1;
  33. tail:=0;
  34. for i:=1 to n do
  35. begin
  36. while true do
  37. begin
  38. read(X);
  39. if x=0 then break;
  40. a[x,i]:=true;
  41. //a[i,x]:=true;
  42. end;
  43. end;
  44. for i:=1 to n do color[i]:=-1;
  45. color[1]:=0;
  46. add(1);
  47. while not empty do
  48.   begin
  49.     v:=poll;
  50.     //writeln(color[v]);
  51.     //writeln(v);
  52.     //writeln(head,' ',tail);
  53.     for i:=1 to n do
  54.       if a[v,i] then if color[i]=color[v] then f:=false
  55.                 else                   begin
  56.                                        color[i]:=(color[v]+1) mod 2;
  57.                                        add(i);
  58.                                        end;
  59.   end;
  60. if f then for i:=1 to n do write(color[i])
  61.      else write(-1);
  62. readln(n);
  63. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement