import java.util.*;
public class supertrees {
public int construct(int[][] p) {
int N = p.length;
for (int[] i: p) {
for (int j: i) {
if (j==3) return 0;
}
}
for (int i = 0; i < N; i++) {
if (p[i][i] != 1) return 0;
}
int[][] ans = new int[N][N];
boolean[] vis = new boolean[N];
boolean[] vis2 = new boolean[N];
ArrayDeque<Integer> bfs = new ArrayDeque<Integer>();
for (int r = 0; r < N; r++) {
if (vis[r])continue;
ArrayList<Integer> comp = new ArrayList<Integer>();
bfs.add(r);
vis[r] = true;
while (!bfs.isEmpty()) {
int i = bfs.pollFirst();
comp.add(i);
for (int j = 0; j < N; j++) {
if (!vis[j] && p[i][j] > 0) {
vis[j] = true;
bfs.add(j);
}
}
}
for (int i: comp) {
for (int j: comp) {
if (p[i][j]==0) return 0;
}
}
ArrayList<Integer> cyc = new ArrayList<Integer>();
for (int c: comp) {
if (vis2[c])continue;
cyc.add(c);
vis2[c] = true;
bfs.add(c);
ArrayList<Integer> sub = new ArrayList<Integer>();
while (!bfs.isEmpty()) {
int i = bfs.pollFirst();
sub.add(i);
for (int j: comp) {
if (!vis2[j] && p[i][j]==1) {
vis2[j] = true;
bfs.add(j);
}
}
}
for (int ind = 1; ind < sub.size(); ind++) {
int i = sub.get(ind-1);
int j = sub.get(ind);
if (i==j)continue;
ans[i][j] = 1;
ans[j][i] = 1;
}
for (int i: sub) {
for (int j: sub) {
if (p[i][j]==2) return 0;
}
}
}
for (int ind = 0; ind < cyc.size(); ind++) {
int i = cyc.get(ind);
int j = cyc.get((ind+1)%cyc.size());
if (i==j)continue;
ans[i][j] = 1;
ans[j][i] = 1;
}
if (cyc.size()==2) return 0;
for (int i: cyc) {
for (int j: cyc) {
if (i!=j && p[i][j]==1) return 0;
}
}
}
grader.build(ans);
return 1;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
8556 KB |
Output is correct |
2 |
Correct |
73 ms |
8556 KB |
Output is correct |
3 |
Correct |
72 ms |
8428 KB |
Output is correct |
4 |
Correct |
73 ms |
8300 KB |
Output is correct |
5 |
Correct |
75 ms |
8684 KB |
Output is correct |
6 |
Correct |
328 ms |
13492 KB |
Output is correct |
7 |
Correct |
511 ms |
36344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
8556 KB |
Output is correct |
2 |
Correct |
73 ms |
8556 KB |
Output is correct |
3 |
Correct |
72 ms |
8428 KB |
Output is correct |
4 |
Correct |
73 ms |
8300 KB |
Output is correct |
5 |
Correct |
75 ms |
8684 KB |
Output is correct |
6 |
Correct |
328 ms |
13492 KB |
Output is correct |
7 |
Correct |
511 ms |
36344 KB |
Output is correct |
8 |
Correct |
75 ms |
8540 KB |
Output is correct |
9 |
Correct |
73 ms |
8428 KB |
Output is correct |
10 |
Correct |
74 ms |
8556 KB |
Output is correct |
11 |
Correct |
72 ms |
8556 KB |
Output is correct |
12 |
Correct |
549 ms |
21288 KB |
Output is correct |
13 |
Correct |
487 ms |
35612 KB |
Output is correct |
14 |
Correct |
74 ms |
8476 KB |
Output is correct |
15 |
Correct |
77 ms |
8556 KB |
Output is correct |
16 |
Correct |
117 ms |
10396 KB |
Output is correct |
17 |
Correct |
150 ms |
18300 KB |
Output is correct |
18 |
Correct |
75 ms |
8556 KB |
Output is correct |
19 |
Correct |
73 ms |
8556 KB |
Output is correct |
20 |
Correct |
404 ms |
24248 KB |
Output is correct |
21 |
Correct |
768 ms |
39540 KB |
Output is correct |
22 |
Correct |
489 ms |
35800 KB |
Output is correct |
23 |
Correct |
496 ms |
36184 KB |
Output is correct |
24 |
Correct |
603 ms |
38396 KB |
Output is correct |
25 |
Correct |
540 ms |
28516 KB |
Output is correct |
26 |
Correct |
233 ms |
24872 KB |
Output is correct |
27 |
Correct |
490 ms |
36028 KB |
Output is correct |
28 |
Correct |
593 ms |
38480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
8428 KB |
Output is correct |
2 |
Correct |
73 ms |
8428 KB |
Output is correct |
3 |
Correct |
73 ms |
8428 KB |
Output is correct |
4 |
Correct |
77 ms |
8400 KB |
Output is correct |
5 |
Correct |
73 ms |
8400 KB |
Output is correct |
6 |
Correct |
76 ms |
8684 KB |
Output is correct |
7 |
Correct |
75 ms |
8556 KB |
Output is correct |
8 |
Correct |
557 ms |
21528 KB |
Output is correct |
9 |
Correct |
467 ms |
37532 KB |
Output is correct |
10 |
Correct |
73 ms |
8556 KB |
Output is correct |
11 |
Correct |
75 ms |
8528 KB |
Output is correct |
12 |
Correct |
373 ms |
16200 KB |
Output is correct |
13 |
Correct |
511 ms |
38000 KB |
Output is correct |
14 |
Correct |
72 ms |
8428 KB |
Output is correct |
15 |
Correct |
75 ms |
8292 KB |
Output is correct |
16 |
Correct |
119 ms |
10524 KB |
Output is correct |
17 |
Correct |
148 ms |
20236 KB |
Output is correct |
18 |
Correct |
74 ms |
8428 KB |
Output is correct |
19 |
Correct |
74 ms |
8556 KB |
Output is correct |
20 |
Correct |
72 ms |
8552 KB |
Output is correct |
21 |
Correct |
439 ms |
26360 KB |
Output is correct |
22 |
Correct |
831 ms |
42032 KB |
Output is correct |
23 |
Correct |
465 ms |
38232 KB |
Output is correct |
24 |
Correct |
500 ms |
38204 KB |
Output is correct |
25 |
Correct |
330 ms |
28040 KB |
Output is correct |
26 |
Correct |
607 ms |
33020 KB |
Output is correct |
27 |
Correct |
467 ms |
37720 KB |
Output is correct |
28 |
Correct |
492 ms |
38076 KB |
Output is correct |
29 |
Correct |
345 ms |
27912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
8428 KB |
Output is correct |
2 |
Correct |
73 ms |
8580 KB |
Output is correct |
3 |
Correct |
75 ms |
8376 KB |
Output is correct |
4 |
Correct |
403 ms |
24132 KB |
Output is correct |
5 |
Correct |
757 ms |
39556 KB |
Output is correct |
6 |
Correct |
465 ms |
35780 KB |
Output is correct |
7 |
Correct |
488 ms |
36048 KB |
Output is correct |
8 |
Correct |
72 ms |
8428 KB |
Output is correct |
9 |
Correct |
442 ms |
25948 KB |
Output is correct |
10 |
Correct |
844 ms |
40312 KB |
Output is correct |
11 |
Correct |
469 ms |
36004 KB |
Output is correct |
12 |
Correct |
512 ms |
36252 KB |
Output is correct |
13 |
Correct |
74 ms |
8408 KB |
Output is correct |
14 |
Correct |
76 ms |
8424 KB |
Output is correct |
15 |
Correct |
76 ms |
8504 KB |
Output is correct |
16 |
Correct |
406 ms |
24148 KB |
Output is correct |
17 |
Correct |
824 ms |
40308 KB |
Output is correct |
18 |
Execution timed out |
1054 ms |
31820 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
8556 KB |
Output is correct |
2 |
Correct |
73 ms |
8556 KB |
Output is correct |
3 |
Correct |
72 ms |
8428 KB |
Output is correct |
4 |
Correct |
73 ms |
8300 KB |
Output is correct |
5 |
Correct |
75 ms |
8684 KB |
Output is correct |
6 |
Correct |
328 ms |
13492 KB |
Output is correct |
7 |
Correct |
511 ms |
36344 KB |
Output is correct |
8 |
Correct |
75 ms |
8540 KB |
Output is correct |
9 |
Correct |
73 ms |
8428 KB |
Output is correct |
10 |
Correct |
74 ms |
8556 KB |
Output is correct |
11 |
Correct |
72 ms |
8556 KB |
Output is correct |
12 |
Correct |
549 ms |
21288 KB |
Output is correct |
13 |
Correct |
487 ms |
35612 KB |
Output is correct |
14 |
Correct |
74 ms |
8476 KB |
Output is correct |
15 |
Correct |
77 ms |
8556 KB |
Output is correct |
16 |
Correct |
117 ms |
10396 KB |
Output is correct |
17 |
Correct |
150 ms |
18300 KB |
Output is correct |
18 |
Correct |
75 ms |
8556 KB |
Output is correct |
19 |
Correct |
73 ms |
8556 KB |
Output is correct |
20 |
Correct |
404 ms |
24248 KB |
Output is correct |
21 |
Correct |
768 ms |
39540 KB |
Output is correct |
22 |
Correct |
489 ms |
35800 KB |
Output is correct |
23 |
Correct |
496 ms |
36184 KB |
Output is correct |
24 |
Correct |
603 ms |
38396 KB |
Output is correct |
25 |
Correct |
540 ms |
28516 KB |
Output is correct |
26 |
Correct |
233 ms |
24872 KB |
Output is correct |
27 |
Correct |
490 ms |
36028 KB |
Output is correct |
28 |
Correct |
593 ms |
38480 KB |
Output is correct |
29 |
Correct |
81 ms |
8428 KB |
Output is correct |
30 |
Correct |
73 ms |
8428 KB |
Output is correct |
31 |
Correct |
73 ms |
8428 KB |
Output is correct |
32 |
Correct |
77 ms |
8400 KB |
Output is correct |
33 |
Correct |
73 ms |
8400 KB |
Output is correct |
34 |
Correct |
76 ms |
8684 KB |
Output is correct |
35 |
Correct |
75 ms |
8556 KB |
Output is correct |
36 |
Correct |
557 ms |
21528 KB |
Output is correct |
37 |
Correct |
467 ms |
37532 KB |
Output is correct |
38 |
Correct |
73 ms |
8556 KB |
Output is correct |
39 |
Correct |
75 ms |
8528 KB |
Output is correct |
40 |
Correct |
373 ms |
16200 KB |
Output is correct |
41 |
Correct |
511 ms |
38000 KB |
Output is correct |
42 |
Correct |
72 ms |
8428 KB |
Output is correct |
43 |
Correct |
75 ms |
8292 KB |
Output is correct |
44 |
Correct |
119 ms |
10524 KB |
Output is correct |
45 |
Correct |
148 ms |
20236 KB |
Output is correct |
46 |
Correct |
74 ms |
8428 KB |
Output is correct |
47 |
Correct |
74 ms |
8556 KB |
Output is correct |
48 |
Correct |
72 ms |
8552 KB |
Output is correct |
49 |
Correct |
439 ms |
26360 KB |
Output is correct |
50 |
Correct |
831 ms |
42032 KB |
Output is correct |
51 |
Correct |
465 ms |
38232 KB |
Output is correct |
52 |
Correct |
500 ms |
38204 KB |
Output is correct |
53 |
Correct |
330 ms |
28040 KB |
Output is correct |
54 |
Correct |
607 ms |
33020 KB |
Output is correct |
55 |
Correct |
467 ms |
37720 KB |
Output is correct |
56 |
Correct |
492 ms |
38076 KB |
Output is correct |
57 |
Correct |
345 ms |
27912 KB |
Output is correct |
58 |
Correct |
77 ms |
8428 KB |
Output is correct |
59 |
Correct |
77 ms |
8544 KB |
Output is correct |
60 |
Correct |
121 ms |
10184 KB |
Output is correct |
61 |
Correct |
150 ms |
20236 KB |
Output is correct |
62 |
Correct |
73 ms |
8428 KB |
Output is correct |
63 |
Correct |
75 ms |
8556 KB |
Output is correct |
64 |
Correct |
73 ms |
8556 KB |
Output is correct |
65 |
Correct |
425 ms |
26536 KB |
Output is correct |
66 |
Correct |
602 ms |
32836 KB |
Output is correct |
67 |
Correct |
674 ms |
33480 KB |
Output is correct |
68 |
Correct |
276 ms |
29720 KB |
Output is correct |
69 |
Correct |
270 ms |
29820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
8556 KB |
Output is correct |
2 |
Correct |
73 ms |
8556 KB |
Output is correct |
3 |
Correct |
72 ms |
8428 KB |
Output is correct |
4 |
Correct |
73 ms |
8300 KB |
Output is correct |
5 |
Correct |
75 ms |
8684 KB |
Output is correct |
6 |
Correct |
328 ms |
13492 KB |
Output is correct |
7 |
Correct |
511 ms |
36344 KB |
Output is correct |
8 |
Correct |
75 ms |
8540 KB |
Output is correct |
9 |
Correct |
73 ms |
8428 KB |
Output is correct |
10 |
Correct |
74 ms |
8556 KB |
Output is correct |
11 |
Correct |
72 ms |
8556 KB |
Output is correct |
12 |
Correct |
549 ms |
21288 KB |
Output is correct |
13 |
Correct |
487 ms |
35612 KB |
Output is correct |
14 |
Correct |
74 ms |
8476 KB |
Output is correct |
15 |
Correct |
77 ms |
8556 KB |
Output is correct |
16 |
Correct |
117 ms |
10396 KB |
Output is correct |
17 |
Correct |
150 ms |
18300 KB |
Output is correct |
18 |
Correct |
75 ms |
8556 KB |
Output is correct |
19 |
Correct |
73 ms |
8556 KB |
Output is correct |
20 |
Correct |
404 ms |
24248 KB |
Output is correct |
21 |
Correct |
768 ms |
39540 KB |
Output is correct |
22 |
Correct |
489 ms |
35800 KB |
Output is correct |
23 |
Correct |
496 ms |
36184 KB |
Output is correct |
24 |
Correct |
603 ms |
38396 KB |
Output is correct |
25 |
Correct |
540 ms |
28516 KB |
Output is correct |
26 |
Correct |
233 ms |
24872 KB |
Output is correct |
27 |
Correct |
490 ms |
36028 KB |
Output is correct |
28 |
Correct |
593 ms |
38480 KB |
Output is correct |
29 |
Correct |
81 ms |
8428 KB |
Output is correct |
30 |
Correct |
73 ms |
8428 KB |
Output is correct |
31 |
Correct |
73 ms |
8428 KB |
Output is correct |
32 |
Correct |
77 ms |
8400 KB |
Output is correct |
33 |
Correct |
73 ms |
8400 KB |
Output is correct |
34 |
Correct |
76 ms |
8684 KB |
Output is correct |
35 |
Correct |
75 ms |
8556 KB |
Output is correct |
36 |
Correct |
557 ms |
21528 KB |
Output is correct |
37 |
Correct |
467 ms |
37532 KB |
Output is correct |
38 |
Correct |
73 ms |
8556 KB |
Output is correct |
39 |
Correct |
75 ms |
8528 KB |
Output is correct |
40 |
Correct |
373 ms |
16200 KB |
Output is correct |
41 |
Correct |
511 ms |
38000 KB |
Output is correct |
42 |
Correct |
72 ms |
8428 KB |
Output is correct |
43 |
Correct |
75 ms |
8292 KB |
Output is correct |
44 |
Correct |
119 ms |
10524 KB |
Output is correct |
45 |
Correct |
148 ms |
20236 KB |
Output is correct |
46 |
Correct |
74 ms |
8428 KB |
Output is correct |
47 |
Correct |
74 ms |
8556 KB |
Output is correct |
48 |
Correct |
72 ms |
8552 KB |
Output is correct |
49 |
Correct |
439 ms |
26360 KB |
Output is correct |
50 |
Correct |
831 ms |
42032 KB |
Output is correct |
51 |
Correct |
465 ms |
38232 KB |
Output is correct |
52 |
Correct |
500 ms |
38204 KB |
Output is correct |
53 |
Correct |
330 ms |
28040 KB |
Output is correct |
54 |
Correct |
607 ms |
33020 KB |
Output is correct |
55 |
Correct |
467 ms |
37720 KB |
Output is correct |
56 |
Correct |
492 ms |
38076 KB |
Output is correct |
57 |
Correct |
345 ms |
27912 KB |
Output is correct |
58 |
Correct |
77 ms |
8428 KB |
Output is correct |
59 |
Correct |
73 ms |
8580 KB |
Output is correct |
60 |
Correct |
75 ms |
8376 KB |
Output is correct |
61 |
Correct |
403 ms |
24132 KB |
Output is correct |
62 |
Correct |
757 ms |
39556 KB |
Output is correct |
63 |
Correct |
465 ms |
35780 KB |
Output is correct |
64 |
Correct |
488 ms |
36048 KB |
Output is correct |
65 |
Correct |
72 ms |
8428 KB |
Output is correct |
66 |
Correct |
442 ms |
25948 KB |
Output is correct |
67 |
Correct |
844 ms |
40312 KB |
Output is correct |
68 |
Correct |
469 ms |
36004 KB |
Output is correct |
69 |
Correct |
512 ms |
36252 KB |
Output is correct |
70 |
Correct |
74 ms |
8408 KB |
Output is correct |
71 |
Correct |
76 ms |
8424 KB |
Output is correct |
72 |
Correct |
76 ms |
8504 KB |
Output is correct |
73 |
Correct |
406 ms |
24148 KB |
Output is correct |
74 |
Correct |
824 ms |
40308 KB |
Output is correct |
75 |
Execution timed out |
1054 ms |
31820 KB |
Time limit exceeded |
76 |
Halted |
0 ms |
0 KB |
- |