1 import java
.io
.PrintWriter
;
2 import java
.io
.FileNotFoundException
;
8 private static final int MAXN
= 100;
10 void printTest(String comment
, List
<List
<Integer
>> edges
) throws FileNotFoundException
{
12 System
.out
.println("Test " + String
.format("%02d", tn
) + ": " + comment
);
13 PrintWriter out
= new PrintWriter(String
.format("%02d", tn
));
14 out
.println(edges
.size());
15 for (List
<Integer
> list
: edges
) {
16 out
.print(list
.size());
26 Random random
= new Random(124234234);
28 void printShuffledTest(String comment
, int[][] a
) throws FileNotFoundException
{
30 List
<Integer
> p
= new ArrayList
<Integer
>();
31 for (int i
= 0; i
< n
; i
++) p
.add(i
);
32 Collections
.shuffle(p
, random
);
33 List
<List
<Integer
>> e
= new ArrayList
<List
<Integer
>>();
34 for (int i
= 0; i
< n
; i
++) {
35 List
<Integer
> list
= new ArrayList
<Integer
>();
36 for (int j
= 0; j
< n
; j
++) {
37 if (a
[p
.get(i
)][p
.get(j
)] > 0) {
41 Collections
.shuffle(list
, random
);
44 printTest(comment
, e
);
47 public static void main(String
[] args
) {
50 } catch (Exception e
) {
56 private void run() throws Exception
{
57 printTest("Sample test",
64 Arrays
.<Integer
>asList(),
66 Arrays
.<Integer
>asList()
69 printShuffledTest("Square",
76 printShuffledTest("Full 4 graph",
83 printShuffledTest("Square and two edges",
92 printShuffledTest("One edge",
98 for (int i
= 0; i
< 10; i
++) {
99 int n
= 5 + random
.nextInt(10);
100 int[][] a
= new int[n
][n
];
101 int m
= random
.nextInt(n
* (n
- 1) / 2 + 1);
102 for (int k
= 0; k
< m
; k
++) {
105 x
= random
.nextInt(n
);
106 y
= random
.nextInt(n
);
107 } while (y
<= x
|| a
[x
][y
] > 0);
110 for (int j
= 0; j
< n
; j
++) {
112 for (int k
= 0; k
< n
; k
++) {
113 if (a
[j
][k
] == 1 || a
[k
][j
] == 1) ok
= true;
115 if (!ok
) a
[j
][(j
+ 1) % n
] = 1;
117 printShuffledTest("Small random test, n = " + n
+ " m = " + m
, a
);
121 for (int zzz
= 0; zzz
< 10; zzz
++) {
122 int[] d
= new int[MAXN
];
123 int[][] a
= new int[MAXN
][MAXN
];
124 boolean[][] b
= new boolean[MAXN
][MAXN
];
125 for (int i
= 0; i
< MAXN
/ 2 - 1; i
++) {
128 x
= random
.nextInt(MAXN
/ 4);
129 y
= MAXN
/ 4 + random
.nextInt(MAXN
/ 4);
136 for (int z
= 0; z
< MAXN
/ 2; z
++) {
147 for (int i
= 0; i
< MAXN
/ 4; i
++) {
148 for (int j
= 0; j
< d
[i
] + 1; j
++) {
149 a
[MAXN
/ 2 + j
][i
] = 1;
152 for (int i
= MAXN
/ 4; i
< MAXN
/ 2; i
++) {
153 for (int j
= 0; j
< d
[i
] + 1; j
++) {
154 a
[i
][MAXN
/ 4 * 3 + j
] = 1;
157 printShuffledTest("Bipartite matching test", a
);
163 int[][] a
= new int[n
][n
];
164 for (int i
= 0; i
< MAXN
- 1; i
++) a
[i
][i
+ 1] = 1;
165 printShuffledTest("One long line", a
);
170 int[][] a
= new int[n
][n
];
171 for (int i
= 0; i
< MAXN
; i
++)
172 for (int j
= i
+ 1; j
< MAXN
&& j
< i
+ 5; j
++) {
175 printShuffledTest("Each node connected with next 5 nodes", a
);
180 int[][] a
= new int[n
][n
];
182 while ((k
+ 1) * (k
+ 1) <= n
) k
++;
183 for (int i
= 0; i
< k
; i
++) {
184 for (int j
= 0; j
< k
; j
++) {
185 if (j
< k
- 1) a
[i
* k
+ j
][i
* k
+ j
+ 1] = 1;
186 if (i
< k
- 1) a
[i
* k
+ j
][i
* k
+ j
+ k
] = 1;
189 for (int i
= k
* k
; i
< n
- 1; i
++) {
192 printShuffledTest("Grid", a
);
197 int[][] a
= new int[n
][n
];
199 while ((m
+ 1) * (m
+ 1) <= n
) m
++;
200 for (int i
= 0; i
< m
; i
++) {
201 for (int j
= 0; j
< m
; j
++) {
202 if (j
< m
- 1 && random
.nextBoolean()) a
[i
* m
+ j
][i
* m
+ j
+ 1] = 1;
203 if (i
< m
- 1 && random
.nextBoolean()) a
[i
* m
+ j
][i
* m
+ j
+ m
] = 1;
206 for (int j
= 0; j
< n
; j
++) {
208 for (int k
= 0; k
< n
; k
++) {
209 if (a
[j
][k
] == 1 || a
[k
][j
] == 1) ok
= true;
211 if (!ok
) a
[j
][(j
+ 1) % n
] = 1;
213 printShuffledTest("Broken grid", a
);
218 int[][] a
= new int[n
][n
];
219 for (int i
= 0; i
< MAXN
; i
++) {
220 for (int j
= i
+ 1; j
< MAXN
; j
++) {
224 printShuffledTest("Full graph", a
);
229 int[][] a
= new int[n
][n
];
230 for (int i
= 0; i
< MAXN
/ 2; i
++) {
231 for (int j
= i
+ 1; j
< MAXN
/ 2; j
++) {
235 a
[MAXN
/ 2 - 1][MAXN
/ 2] = 1;
236 for (int i
= MAXN
/ 2; i
< MAXN
; i
++) {
237 for (int j
= i
+ 1; j
< MAXN
; j
++) {
241 printShuffledTest("Two connected full graphs", a
);
246 int[][] a
= new int[n
][n
];
247 for (int i
= 0; i
< MAXN
/ 4; i
++) {
248 for (int j
= MAXN
/ 4; j
< MAXN
/ 2; j
++) {
252 for (int i
= MAXN
/ 4; i
< MAXN
/ 2; i
++) {
253 a
[i
][i
+ MAXN
/ 4] = 1;
255 for (int i
= MAXN
/ 2; i
< MAXN
/ 4 * 3; i
++) {
256 for (int j
= MAXN
/ 4 * 3; j
< MAXN
; j
++) {
260 printShuffledTest("Two connected bipartite full graphs", a
);
265 int[][] a
= new int[n
][n
];
266 for (int k
= 0; k
< MAXN
/ 10; k
++) {
267 for (int i
= 0; i
< 10; i
++) {
268 for (int j
= i
+ 1; j
< 10; j
++) {
269 a
[k
* 10 + i
][k
* 10 + j
] = 1;
273 int j
= random
.nextInt(k
);
274 a
[j
* 10 + 9][k
* 10] = 1;
277 printShuffledTest("10 connected full graphs", a
);
282 int[][] a
= new int[n
][n
];
283 for (int i
= 0; i
< MAXN
/ 2; i
++) {
284 for (int j
= MAXN
/ 2; j
< MAXN
; j
++) {
288 printShuffledTest("Full bipartite graph", a
);
293 while ((m
+ 1) * (m
+ 1) <= MAXN
) m
++;
295 int[][] a
= new int[n
][n
];
296 for (int i
= 0; i
< m
- 1; i
++) {
297 for (int j
= 0; j
< m
; j
++) {
298 for (int k
= 0; j
< m
; j
++) {
299 a
[i
* m
+ j
][i
* m
+ k
+ m
] = 1;
303 printShuffledTest("Full layered graph", a
);
308 while (n
% 5 > 0) n
--;
310 int[][] a
= new int[n
][n
];
311 for (int i
= 0; i
< m
; i
++) {
312 for (int j
= m
; j
< 2 * m
; j
++) {
316 for (int j
= m
; j
< 2 * m
; j
++) {
319 for (int i
= 2 * m
; i
< 3 * m
- 1; i
++) {
322 for (int j
= 4 * m
; j
< 5 * m
; j
++) {
325 for (int i
= 3 * m
; i
< 4 * m
; i
++) {
326 for (int j
= 4 * m
; j
< 5 * m
; j
++) {
330 printShuffledTest("Many long paths", a
);
333 for (int i
= 0; i
< 10; i
++) {
334 int n
= MAXN
- random
.nextInt(5);
335 int[][] a
= new int[n
][n
];
336 for (int j
= 1; j
< n
; j
++) {
337 int k
= random
.nextInt(j
);
340 printShuffledTest("Random tree", a
);
343 for (int i
= 0; i
< 20; i
++) {
344 int n
= MAXN
- random
.nextInt(5);
345 int[][] a
= new int[n
][n
];
346 int m
= random
.nextInt(n
* (n
- 1) / 2 + 1);
347 for (int k
= 0; k
< m
; k
++) {
350 x
= random
.nextInt(n
);
351 y
= random
.nextInt(n
);
352 } while (y
<= x
|| a
[x
][y
] > 0);
355 for (int j
= 0; j
< n
; j
++) {
357 for (int k
= 0; k
< n
; k
++) {
358 if (a
[j
][k
] == 1 || a
[k
][j
] == 1) ok
= true;
360 if (!ok
) a
[j
][(j
+ 1) % n
] = 1;
362 printShuffledTest("Random test, n = " + n
+ " m = " + m
, a
);
364 //To change body of created methods use File | Settings | File Templates.