fork download
  1. program subjects;
  2.  
  3. const
  4. MAXN = 100000;
  5. MAXM = 1000;
  6.  
  7. var
  8. M, N, P, i, j, h: LongInt;
  9. K : Array[0..MAXN-1] of LongInt;
  10. S : Array[0..MAXN-1] of Array[0..4] of LongInt;
  11. ans : Array[1..MAXM] of Array[1..2] of LongInt;
  12. coppie : Array[1..MAXM,1..MAXM] of LongInt;
  13. materia : Array[1..MAXM] of boolean;
  14.  
  15. begin
  16. (*assign(input, 'input.txt'); reset(input);
  17.   assign(output, 'output.txt'); rewrite(output);*)
  18.  
  19. ReadLn(N, M);
  20.  
  21. for i:=1 to M do materia[i]:=false;
  22.  
  23. for i := 0 to N - 1 do
  24. begin
  25. Read(K[i]);
  26. for j := 0 to K[i] - 1 do
  27. begin
  28. Read(S[i][j]);
  29. materia[S[i][j]]:=true;
  30. end;
  31.  
  32. end;
  33. for i:=1 to M do
  34. for j:=1 to M do coppie[i,j]:=0;
  35. P:=0;
  36. for i:=0 to N-1 do
  37. begin
  38. for j:=0 to K[i]-1 do
  39. for h:= j+1 to K[i]-1 do
  40. begin
  41. coppie[S[i][j],S[i][h]]:=coppie[S[i][j],S[i][h]]+1;
  42. coppie[S[i][h],S[i][j]]:=coppie[S[i][h],S[i][j]]+1;
  43. end;
  44. end;
  45.  
  46. for i:=1 to M do
  47. for j:= 1 to M do
  48. if (coppie[i,j]=0) and (i<j) then
  49. begin
  50. P:=P+1;
  51. ans[P][1]:=i; ans[P][2]:=j;
  52. end;
  53.  
  54. WriteLn(P);
  55. for i := 1 to P do
  56. begin
  57. for j := 1 to 2 do
  58. Write(ans[i][j], ' ');
  59. WriteLn();
  60. end;
  61.  
  62. end.
Success #stdin #stdout 0.01s 5280KB
stdin
3 5
2 1 2
2 5 4
2 3 4
stdout
7
1 3 
1 4 
1 5 
2 3 
2 4 
2 5 
3 5