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. materia : Array[1..MAXM] of boolean;
  11. S : Array[0..MAXN-1] of Array[0..5] of LongInt;
  12. ans : Array[0..MAXM-1] of Array[0..1] of LongInt;
  13. coppie : Array[1..MAXM,1..MAXM] of LongInt;
  14.  
  15.  
  16. begin
  17. {
  18.   uncomment the two following lines if you want to read/write from files
  19.   assign(input, 'input.txt'); reset(input);
  20.   assign(output, 'output.txt'); rewrite(output);
  21. }
  22.  
  23. ReadLn(N, M);
  24.  
  25. for i:=1 to M do materia[i]:=false;
  26.  
  27. for i := 0 to N - 1 do
  28. begin
  29. Read(K[i]);
  30. for j := 0 to K[i] - 1 do
  31. begin
  32. Read(S[i][j]);
  33. materia[S[i][j]]:=true;
  34. end;
  35. end;
  36. for i:=1 to M do
  37. for j:=1 to M do coppie[i,j]:=0;
  38. P:=0;
  39. for i:=0 to N-1 do
  40. begin
  41. if K[i]>=1 then
  42. begin
  43. for j:=0 to K[i]-1 do
  44. for h:= j+1 to K[i]-1 do
  45. begin
  46. coppie[S[i][j],S[i][h]]:=coppie[S[i][j],S[i][h]]+1;
  47. coppie[S[i][h],S[i][j]]:=coppie[S[i][h],S[i][j]]+1;
  48. end;
  49. end;
  50. end;
  51.  
  52. for i:=1 to M do
  53. for j:= 1 to M do
  54. if (coppie[i,j]=0) and (i<j) then
  55. begin
  56. P:=P+1;
  57. ans[P][1]:=i; ans[P][2]:=j;
  58. end;
  59.  
  60. WriteLn(P);
  61. for i := 1 to P do
  62. begin
  63. for j := 1 to 2 do
  64. Write(ans[i][j], ' ');
  65. WriteLn();
  66. end;
  67. end.
  68.  
Success #stdin #stdout 0s 5284KB
stdin
4 4
1 2
1 3
1 2
1 3
stdout
6
1 2 
1 3 
1 4 
2 3 
2 4 
3 4