Under construction

Still being built. Things may change

Router 1

Time limit2sMemory limit512 MB

Summary
Print either a star-shaped router with one internal hub or a fully connected bipartite router, depending on whether N*N exceeds P_lim.
Level

Easy3 of 10

Topics
Graph, Implementation, Simulation
Solved
No attempts yet

Problem

Henry and Hetty were hired by a networking company. Their first project is a new router, the Connect Ethernet Operating Interface, built from:

  • NN input nodes, numbered from 11 to NN;
  • NN output nodes, numbered from N+1N+1 to 2N2N;
  • KK internal nodes, numbered from 2N+12N+1 to 2N+K2N+K;
  • MM unidirectional direct connections, each joining two distinct nodes.

A node XX can send data to a node YY (equivalently, YY can receive data from XX) if one of the following holds:

  • X=YX = Y;
  • there is a node ZZ such that XX can send data to ZZ and a direct connection runs from ZZ to YY.

If XX can send data to YY and X≠YX \ne Y, the data path from XX to YY is the set of direct connections {(A1,A2),(A2,A3),…,(AL−1,AL)}\{(A_1, A_2), (A_2, A_3), \ldots, (A_{L-1}, A_L)\} with L≥2L \ge 2, A1=XA_1 = X and AL=YA_L = Y.

A router works properly when all of the following hold:

  • every input node can send data to every output node;
  • every input node can receive data only from itself;
  • every output node can send data only to itself;
  • for any two nodes XX and YY with X≠YX \ne Y, if XX can send data to YY, then YY cannot send data to XX;
  • for any two nodes XX and YY with X≠YX \ne Y, if XX can send data to YY, then the data path from XX to YY is unique. In particular, any two nodes are joined by at most one direct connection.

The power needed to operate node XX is PX=INX×OUTXP_X = IN_X \times OUT_X, where INXIN_X is the number of input nodes that can send data to XX and OUTXOUT_X is the number of output nodes that can receive data from XX. Writing Ntot=2N+KN_{tot} = 2N + K for the total number of nodes, the maximum power used by the router is Pmax=max⁡(P1,P2,…,PNtot)P_{max} = \max(P_1, P_2, \ldots, P_{N_{tot}}).

You are given NN, MlimM_{lim} and PlimP_{lim}. Build a router that works properly, has exactly NN input nodes and NN output nodes, uses at most MlimM_{lim} direct connections, has Pmax≤PlimP_{max} \le P_{lim}, and uses at most 500 000500\,000 nodes in total. Several routers meet such a specification, so the output section fixes the single one you must print.

Input

One line with three integers NN, MlimM_{lim} and PlimP_{lim}: the number of input nodes and of output nodes, the largest number of direct connections allowed, and the largest power the router may use (1≤N≤10001 \le N \le 1000, 1≤Mlim≤1061 \le M_{lim} \le 10^6, 1≤Plim≤1061 \le P_{lim} \le 10^6).

It is guaranteed that N≤PlimN \le P_{lim} and that the router described in the output section uses at most MlimM_{lim} direct connections.

Output

Print the router picked by the rule below.

If N×N≤PlimN \times N \le P_{lim}, print the router with one internal node. It has Ntot=2N+1N_{tot} = 2N + 1 nodes and M=2NM = 2N direct connections: first the connections i→2N+1i \to 2N+1 for i=1,2,…,Ni = 1, 2, \ldots, N in increasing order of ii, then the connections 2N+1→N+j2N+1 \to N+j for j=1,2,…,Nj = 1, 2, \ldots, N in increasing order of jj.

Otherwise print the router with no internal node. It has Ntot=2NN_{tot} = 2N nodes and M=N×NM = N \times N direct connections, namely i→N+ji \to N+j for every pair (i,j)(i, j), sorted by ii increasing and, for equal ii, by jj increasing.

The first line holds NtotN_{tot} and MM separated by a space. Each of the next MM lines holds two integers XX and YY, meaning a direct connection from node XX to node YY was built.

Examples6

  1. Example 1

    Input
    3 100 200
    
    Expected output
    7 6
    1 7
    2 7
    3 7
    7 4
    7 5
    7 6
    
  2. Example 2

    Input
    1 1000000 1000000
    
    Expected output
    3 2
    1 3
    3 2
    
  3. Example 3

    Input
    2 100 3
    
    Expected output
    4 4
    1 3
    1 4
    2 3
    2 4
    
  4. Example 4

    Input
    5 1000000 25
    
    Expected output
    11 10
    1 11
    2 11
    3 11
    4 11
    5 11
    11 6
    11 7
    11 8
    11 9
    11 10
    
  5. Example 5

    Input
    5 1000000 24
    
    Expected output
    10 25
    1 6
    1 7
    1 8
    1 9
    1 10
    2 6
    2 7
    2 8
    2 9
    2 10
    3 6
    3 7
    3 8
    3 9
    3 10
    4 6
    4 7
    4 8
    4 9
    4 10
    5 6
    5 7
    5 8
    5 9
    5 10
    
  6. Example 6

    Input
    118 1000000 1000000
    
    Expected output
    237 236
    1 237
    2 237
    3 237
    4 237
    5 237
    6 237
    7 237
    8 237
    9 237
    10 237
    11 237
    12 237
    13 237
    14 237
    15 237
    16 237
    17 237
    18 237
    19 237
    20 237
    21 237
    22 237
    23 237
    24 237
    25 237
    26 237
    27 237
    28 237
    29 237
    30 237
    31 237
    32 237
    33 237
    34 237
    35 237
    36 237
    37 237
    38 237
    39 237
    40 237
    41 237
    42 237
    43 237
    44 237
    45 237
    46 237
    47 237
    48 237
    49 237
    50 237
    51 237
    52 237
    53 237
    54 237
    55 237
    56 237
    57 237
    58 237
    59 237
    60 237
    61 237
    62 237
    63 237
    64 237
    65 237
    66 237
    67 237
    68 237
    69 237
    70 237
    71 237
    72 237
    73 237
    74 237
    75 237
    76 237
    77 237
    78 237
    79 237
    80 237
    81 237
    82 237
    83 237
    84 237
    85 237
    86 237
    87 237
    88 237
    89 237
    90 237
    91 237
    92 237
    93 237
    94 237
    95 237
    96 237
    97 237
    98 237
    99 237
    100 237
    101 237
    102 237
    103 237
    104 237
    105 237
    106 237
    107 237
    108 237
    109 237
    110 237
    111 237
    112 237
    113 237
    114 237
    115 237
    116 237
    117 237
    118 237
    237 119
    237 120
    237 121
    237 122
    237 123
    237 124
    237 125
    237 126
    237 127
    237 128
    237 129
    237 130
    237 131
    237 132
    237 133
    237 134
    237 135
    237 136
    237 137
    237 138
    237 139
    237 140
    237 141
    237 142
    237 143
    237 144
    237 145
    237 146
    237 147
    237 148
    237 149
    237 150
    237 151
    237 152
    237 153
    237 154
    237 155
    237 156
    237 157
    237 158
    237 159
    237 160
    237 161
    237 162
    237 163
    237 164
    237 165
    237 166
    237 167
    237 168
    237 169
    237 170
    237 171
    237 172
    237 173
    237 174
    237 175
    237 176
    237 177
    237 178
    237 179
    237 180
    237 181
    237 182
    237 183
    237 184
    237 185
    237 186
    237 187
    237 188
    237 189
    237 190
    237 191
    237 192
    237 193
    237 194
    237 195
    237 196
    237 197
    237 198
    237 199
    237 200
    237 201
    237 202
    237 203
    237 204
    237 205
    237 206
    237 207
    237 208
    237 209
    237 210
    237 211
    237 212
    237 213
    237 214
    237 215
    237 216
    237 217
    237 218
    237 219
    237 220
    237 221
    237 222
    237 223
    237 224
    237 225
    237 226
    237 227
    237 228
    237 229
    237 230
    237 231
    237 232
    237 233
    237 234
    237 235
    237 236