fork(2) download
  1.  
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. #define REP(i, a, b) for (int i = a; i <= b; i++)
  6. #define FOR(i, n) for (int i = 0; i < n; i++)
  7. #define foreach(it, ar) for ( typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++ )
  8. #define fill(ar, val) memset(ar, val, sizeof(ar))
  9. #define PI 3.1415926535897932385
  10. #define uint64 unsigned long long
  11. #define Int long long
  12. #define int64 long long
  13. #define all(ar) ar.begin(), ar.end()
  14. #define pb push_back
  15. #define ff first
  16. #define ss second
  17. #define bit(n) (1<<(n))
  18. #define Last(i) ( (i) & (-i) )
  19. #define sq(x) ((x) * (x))
  20. #define INF INT_MAX
  21. #define mp make_pair
  22.  
  23.  
  24.  
  25. int main ( )
  26. {
  27. int t ;
  28. scanf("%d",&t) ;
  29. while( t-- )
  30. {
  31. int g [ 100 ][ 100 ] ;
  32. FOR( i , 100) FOR( j , 100 )g[i][j] = 0 ;
  33. int cnt1[ 100 ] = { 0 } ;
  34. int cnt2 [ 100 ] = { 0 } ;
  35.  
  36. int n , m , d, D ;
  37. scanf("%d%d%d%d",&n,&m,&d,&D) ;
  38.  
  39. set< pair<int,int> > s ;
  40.  
  41. FOR( i , n )
  42. s.insert( mp(0,i) ) ;
  43.  
  44. FOR( i , n )
  45. {
  46.  
  47. for( int j = 1 ; j <= d ; j ++ )
  48. {
  49. auto it = s.begin() ;
  50. pair<int,int> tp = mp( it->ff + 1 , it->ss ) ;
  51.  
  52. g[ i ][ it->ss ] = 1 ;
  53.  
  54. cnt1[i] ++ ;
  55. cnt2[it->ss] ++ ;
  56.  
  57. s.erase( it ) ;
  58. s.insert( tp ) ;
  59.  
  60. //it->ff += 1 ;
  61.  
  62. }
  63.  
  64.  
  65. }
  66.  
  67. int rem = m - n*d ;
  68.  
  69. for( int i = 0 ; i < n ; i ++ )
  70. for( int j = 0 ; j < n ; j ++ )
  71. {
  72. if( g[i][j] == 0 && cnt1[i] < D && cnt2[j] < D && rem > 0 )
  73. {
  74. cnt1[i] ++ ;
  75. g[i][j] = 1 ;
  76. cnt2[j] ++ ;
  77. rem -- ;
  78.  
  79. }
  80.  
  81. }
  82.  
  83. bool f = false ;
  84. for( int i = 0 ; i < n ; i ++ )
  85. {
  86. if( cnt1[i] < d || cnt1[i] > D )
  87. { f = true ; break; }
  88.  
  89. if( cnt2[i] < d || cnt2[i] > D )
  90. { f = true ; break; }
  91.  
  92. }
  93.  
  94.  
  95. if( f || (rem != 0) ) {cout<<-1<<'\n' ; continue ; }
  96.  
  97. for( int i = 0 ; i < n ; i ++ )
  98. for( int j= 0 ; j < n ; j ++ )
  99. if( g[i][j] == 1 )
  100. cout<<i+1 << " " << j + 1 <<'\n' ;
  101.  
  102.  
  103.  
  104. }
  105.  
  106. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
Standard output is empty