// yanhao-full
import java.util.ArrayList;
import java.util.Arrays;
class supertrees {
int n;
int construct(int[][] p) {
n = p.length;
ArrayList<ArrayList<Integer>> components1 = new ArrayList<>();
ArrayList<ArrayList<Integer>> components2 = new ArrayList<>();
for(int i=0; i<n; i++) components1.add(new ArrayList<>());
for(int i=0; i<n; i++) components2.add(new ArrayList<>());
for(int i=0; i<n; i++) {
for(int j=0; j<n; j++) {
if(p[i][j]==3) return 0;
}
}
int[] parent1 = new int[n];
int[] parent2 = new int[n];
for(int i=0; i<n; i++) {
parent1[i] = i;
parent2[i] = i;
}
for(int i=0; i<n; i++) {
for(int j=0; j<n; j++) {
if(p[i][j]==1) {
parent1[i] = j;
components1.get(j).add(i);
break;
}
}
}
for(int i=0; i<n; i++) {
if(parent1[i]!=i) continue;
for(int j=0; j<n; j++) {
if(parent1[j]!=j) continue;
if(p[i][j]==2 || i==j) {
parent2[i] = j;
components2.get(j).add(i);
break;
}
}
}
int[][] b = new int[n][n];
for(int i=0; i<n; i++) {
for(int j=0; j<n; j++) {
b[i][j] = 0;
}
}
for(int i=0; i<n; i++) {
ArrayList<Integer> cmp = components1.get(i);
// impossiblility check for 1s
for(int j=1; j<cmp.size(); j++) {
if(!Arrays.equals(p[cmp.get(j)], p[cmp.get(0)])) {
return 0;
}
b[cmp.get(j)][cmp.get(0)] = 1;
b[cmp.get(0)][cmp.get(j)] = 1;
}
// impossibility check for 2s
cmp = components2.get(i);
if(cmp.size()==2) {
return 0;
}
if(cmp.size()<2) continue;
for(int j=0; j<cmp.size(); j++) {
for(int k=0; k<j; k++) {
if(p[cmp.get(j)][cmp.get(k)]!=2) {
return 0;
}
}
}
for(int j=1; j<cmp.size(); j++) {
b[cmp.get(j)][cmp.get(j-1)] = 1;
b[cmp.get(j-1)][cmp.get(j)] = 1;
}
b[cmp.get(0)][cmp.get(cmp.size()-1)] = 1;
b[cmp.get(cmp.size()-1)][cmp.get(0)] = 1;
}
for(int i=0; i<n; i++) {
for(int j=0; j<n; j++) {
if(p[i][j]==1 && parent1[i]!=parent1[j]) return 0;
if(p[i][j]==2 && parent2[parent1[i]]!=parent2[parent1[j]]) return 0;
}
}
grader.build(b);
return 1;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
97 ms |
10124 KB |
Output is correct |
2 |
Correct |
77 ms |
9976 KB |
Output is correct |
3 |
Correct |
91 ms |
10144 KB |
Output is correct |
4 |
Correct |
83 ms |
10156 KB |
Output is correct |
5 |
Correct |
90 ms |
10208 KB |
Output is correct |
6 |
Correct |
202 ms |
16260 KB |
Output is correct |
7 |
Correct |
476 ms |
57184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
97 ms |
10124 KB |
Output is correct |
2 |
Correct |
77 ms |
9976 KB |
Output is correct |
3 |
Correct |
91 ms |
10144 KB |
Output is correct |
4 |
Correct |
83 ms |
10156 KB |
Output is correct |
5 |
Correct |
90 ms |
10208 KB |
Output is correct |
6 |
Correct |
202 ms |
16260 KB |
Output is correct |
7 |
Correct |
476 ms |
57184 KB |
Output is correct |
8 |
Correct |
87 ms |
10288 KB |
Output is correct |
9 |
Correct |
79 ms |
10232 KB |
Output is correct |
10 |
Correct |
78 ms |
10216 KB |
Output is correct |
11 |
Correct |
88 ms |
10392 KB |
Output is correct |
12 |
Correct |
190 ms |
16352 KB |
Output is correct |
13 |
Correct |
522 ms |
60572 KB |
Output is correct |
14 |
Correct |
85 ms |
10224 KB |
Output is correct |
15 |
Correct |
82 ms |
10308 KB |
Output is correct |
16 |
Correct |
109 ms |
11128 KB |
Output is correct |
17 |
Correct |
177 ms |
21520 KB |
Output is correct |
18 |
Correct |
84 ms |
10172 KB |
Output is correct |
19 |
Correct |
83 ms |
10092 KB |
Output is correct |
20 |
Correct |
390 ms |
30168 KB |
Output is correct |
21 |
Correct |
486 ms |
57208 KB |
Output is correct |
22 |
Correct |
550 ms |
60100 KB |
Output is correct |
23 |
Correct |
569 ms |
59288 KB |
Output is correct |
24 |
Correct |
486 ms |
59968 KB |
Output is correct |
25 |
Correct |
191 ms |
22104 KB |
Output is correct |
26 |
Correct |
205 ms |
21604 KB |
Output is correct |
27 |
Correct |
548 ms |
60528 KB |
Output is correct |
28 |
Correct |
446 ms |
57456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
10112 KB |
Output is correct |
2 |
Correct |
82 ms |
10228 KB |
Output is correct |
3 |
Correct |
81 ms |
10104 KB |
Output is correct |
4 |
Correct |
79 ms |
10096 KB |
Output is correct |
5 |
Correct |
85 ms |
10156 KB |
Output is correct |
6 |
Correct |
89 ms |
10100 KB |
Output is correct |
7 |
Correct |
88 ms |
10228 KB |
Output is correct |
8 |
Correct |
202 ms |
16140 KB |
Output is correct |
9 |
Correct |
536 ms |
60612 KB |
Output is correct |
10 |
Correct |
85 ms |
10104 KB |
Output is correct |
11 |
Correct |
84 ms |
10356 KB |
Output is correct |
12 |
Correct |
204 ms |
16508 KB |
Output is correct |
13 |
Correct |
613 ms |
58284 KB |
Output is correct |
14 |
Correct |
86 ms |
10344 KB |
Output is correct |
15 |
Correct |
82 ms |
9992 KB |
Output is correct |
16 |
Correct |
107 ms |
10860 KB |
Output is correct |
17 |
Correct |
197 ms |
21500 KB |
Output is correct |
18 |
Correct |
84 ms |
10104 KB |
Output is correct |
19 |
Correct |
80 ms |
10488 KB |
Output is correct |
20 |
Correct |
80 ms |
10136 KB |
Output is correct |
21 |
Correct |
394 ms |
25920 KB |
Output is correct |
22 |
Correct |
622 ms |
60916 KB |
Output is correct |
23 |
Correct |
532 ms |
60428 KB |
Output is correct |
24 |
Correct |
511 ms |
59112 KB |
Output is correct |
25 |
Correct |
186 ms |
22236 KB |
Output is correct |
26 |
Correct |
202 ms |
22268 KB |
Output is correct |
27 |
Correct |
514 ms |
57752 KB |
Output is correct |
28 |
Correct |
527 ms |
59752 KB |
Output is correct |
29 |
Correct |
197 ms |
22536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
10104 KB |
Output is correct |
2 |
Correct |
79 ms |
10208 KB |
Output is correct |
3 |
Correct |
82 ms |
10236 KB |
Output is correct |
4 |
Correct |
339 ms |
25804 KB |
Output is correct |
5 |
Correct |
522 ms |
59712 KB |
Output is correct |
6 |
Correct |
507 ms |
59920 KB |
Output is correct |
7 |
Correct |
516 ms |
60256 KB |
Output is correct |
8 |
Correct |
83 ms |
10208 KB |
Output is correct |
9 |
Correct |
379 ms |
29040 KB |
Output is correct |
10 |
Correct |
544 ms |
59676 KB |
Output is correct |
11 |
Correct |
517 ms |
60084 KB |
Output is correct |
12 |
Correct |
524 ms |
58680 KB |
Output is correct |
13 |
Correct |
79 ms |
10140 KB |
Output is correct |
14 |
Correct |
79 ms |
10232 KB |
Output is correct |
15 |
Correct |
103 ms |
10024 KB |
Output is correct |
16 |
Correct |
366 ms |
26796 KB |
Output is correct |
17 |
Correct |
514 ms |
60124 KB |
Output is correct |
18 |
Correct |
503 ms |
58476 KB |
Output is correct |
19 |
Correct |
628 ms |
60088 KB |
Output is correct |
20 |
Correct |
506 ms |
60068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
97 ms |
10124 KB |
Output is correct |
2 |
Correct |
77 ms |
9976 KB |
Output is correct |
3 |
Correct |
91 ms |
10144 KB |
Output is correct |
4 |
Correct |
83 ms |
10156 KB |
Output is correct |
5 |
Correct |
90 ms |
10208 KB |
Output is correct |
6 |
Correct |
202 ms |
16260 KB |
Output is correct |
7 |
Correct |
476 ms |
57184 KB |
Output is correct |
8 |
Correct |
87 ms |
10288 KB |
Output is correct |
9 |
Correct |
79 ms |
10232 KB |
Output is correct |
10 |
Correct |
78 ms |
10216 KB |
Output is correct |
11 |
Correct |
88 ms |
10392 KB |
Output is correct |
12 |
Correct |
190 ms |
16352 KB |
Output is correct |
13 |
Correct |
522 ms |
60572 KB |
Output is correct |
14 |
Correct |
85 ms |
10224 KB |
Output is correct |
15 |
Correct |
82 ms |
10308 KB |
Output is correct |
16 |
Correct |
109 ms |
11128 KB |
Output is correct |
17 |
Correct |
177 ms |
21520 KB |
Output is correct |
18 |
Correct |
84 ms |
10172 KB |
Output is correct |
19 |
Correct |
83 ms |
10092 KB |
Output is correct |
20 |
Correct |
390 ms |
30168 KB |
Output is correct |
21 |
Correct |
486 ms |
57208 KB |
Output is correct |
22 |
Correct |
550 ms |
60100 KB |
Output is correct |
23 |
Correct |
569 ms |
59288 KB |
Output is correct |
24 |
Correct |
486 ms |
59968 KB |
Output is correct |
25 |
Correct |
191 ms |
22104 KB |
Output is correct |
26 |
Correct |
205 ms |
21604 KB |
Output is correct |
27 |
Correct |
548 ms |
60528 KB |
Output is correct |
28 |
Correct |
446 ms |
57456 KB |
Output is correct |
29 |
Correct |
84 ms |
10112 KB |
Output is correct |
30 |
Correct |
82 ms |
10228 KB |
Output is correct |
31 |
Correct |
81 ms |
10104 KB |
Output is correct |
32 |
Correct |
79 ms |
10096 KB |
Output is correct |
33 |
Correct |
85 ms |
10156 KB |
Output is correct |
34 |
Correct |
89 ms |
10100 KB |
Output is correct |
35 |
Correct |
88 ms |
10228 KB |
Output is correct |
36 |
Correct |
202 ms |
16140 KB |
Output is correct |
37 |
Correct |
536 ms |
60612 KB |
Output is correct |
38 |
Correct |
85 ms |
10104 KB |
Output is correct |
39 |
Correct |
84 ms |
10356 KB |
Output is correct |
40 |
Correct |
204 ms |
16508 KB |
Output is correct |
41 |
Correct |
613 ms |
58284 KB |
Output is correct |
42 |
Correct |
86 ms |
10344 KB |
Output is correct |
43 |
Correct |
82 ms |
9992 KB |
Output is correct |
44 |
Correct |
107 ms |
10860 KB |
Output is correct |
45 |
Correct |
197 ms |
21500 KB |
Output is correct |
46 |
Correct |
84 ms |
10104 KB |
Output is correct |
47 |
Correct |
80 ms |
10488 KB |
Output is correct |
48 |
Correct |
80 ms |
10136 KB |
Output is correct |
49 |
Correct |
394 ms |
25920 KB |
Output is correct |
50 |
Correct |
622 ms |
60916 KB |
Output is correct |
51 |
Correct |
532 ms |
60428 KB |
Output is correct |
52 |
Correct |
511 ms |
59112 KB |
Output is correct |
53 |
Correct |
186 ms |
22236 KB |
Output is correct |
54 |
Correct |
202 ms |
22268 KB |
Output is correct |
55 |
Correct |
514 ms |
57752 KB |
Output is correct |
56 |
Correct |
527 ms |
59752 KB |
Output is correct |
57 |
Correct |
197 ms |
22536 KB |
Output is correct |
58 |
Correct |
77 ms |
10228 KB |
Output is correct |
59 |
Correct |
79 ms |
10100 KB |
Output is correct |
60 |
Correct |
106 ms |
11128 KB |
Output is correct |
61 |
Correct |
186 ms |
21804 KB |
Output is correct |
62 |
Correct |
83 ms |
10000 KB |
Output is correct |
63 |
Correct |
81 ms |
10196 KB |
Output is correct |
64 |
Correct |
80 ms |
10004 KB |
Output is correct |
65 |
Correct |
354 ms |
27452 KB |
Output is correct |
66 |
Correct |
194 ms |
21848 KB |
Output is correct |
67 |
Correct |
175 ms |
22000 KB |
Output is correct |
68 |
Correct |
191 ms |
22292 KB |
Output is correct |
69 |
Correct |
181 ms |
22120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
97 ms |
10124 KB |
Output is correct |
2 |
Correct |
77 ms |
9976 KB |
Output is correct |
3 |
Correct |
91 ms |
10144 KB |
Output is correct |
4 |
Correct |
83 ms |
10156 KB |
Output is correct |
5 |
Correct |
90 ms |
10208 KB |
Output is correct |
6 |
Correct |
202 ms |
16260 KB |
Output is correct |
7 |
Correct |
476 ms |
57184 KB |
Output is correct |
8 |
Correct |
87 ms |
10288 KB |
Output is correct |
9 |
Correct |
79 ms |
10232 KB |
Output is correct |
10 |
Correct |
78 ms |
10216 KB |
Output is correct |
11 |
Correct |
88 ms |
10392 KB |
Output is correct |
12 |
Correct |
190 ms |
16352 KB |
Output is correct |
13 |
Correct |
522 ms |
60572 KB |
Output is correct |
14 |
Correct |
85 ms |
10224 KB |
Output is correct |
15 |
Correct |
82 ms |
10308 KB |
Output is correct |
16 |
Correct |
109 ms |
11128 KB |
Output is correct |
17 |
Correct |
177 ms |
21520 KB |
Output is correct |
18 |
Correct |
84 ms |
10172 KB |
Output is correct |
19 |
Correct |
83 ms |
10092 KB |
Output is correct |
20 |
Correct |
390 ms |
30168 KB |
Output is correct |
21 |
Correct |
486 ms |
57208 KB |
Output is correct |
22 |
Correct |
550 ms |
60100 KB |
Output is correct |
23 |
Correct |
569 ms |
59288 KB |
Output is correct |
24 |
Correct |
486 ms |
59968 KB |
Output is correct |
25 |
Correct |
191 ms |
22104 KB |
Output is correct |
26 |
Correct |
205 ms |
21604 KB |
Output is correct |
27 |
Correct |
548 ms |
60528 KB |
Output is correct |
28 |
Correct |
446 ms |
57456 KB |
Output is correct |
29 |
Correct |
84 ms |
10112 KB |
Output is correct |
30 |
Correct |
82 ms |
10228 KB |
Output is correct |
31 |
Correct |
81 ms |
10104 KB |
Output is correct |
32 |
Correct |
79 ms |
10096 KB |
Output is correct |
33 |
Correct |
85 ms |
10156 KB |
Output is correct |
34 |
Correct |
89 ms |
10100 KB |
Output is correct |
35 |
Correct |
88 ms |
10228 KB |
Output is correct |
36 |
Correct |
202 ms |
16140 KB |
Output is correct |
37 |
Correct |
536 ms |
60612 KB |
Output is correct |
38 |
Correct |
85 ms |
10104 KB |
Output is correct |
39 |
Correct |
84 ms |
10356 KB |
Output is correct |
40 |
Correct |
204 ms |
16508 KB |
Output is correct |
41 |
Correct |
613 ms |
58284 KB |
Output is correct |
42 |
Correct |
86 ms |
10344 KB |
Output is correct |
43 |
Correct |
82 ms |
9992 KB |
Output is correct |
44 |
Correct |
107 ms |
10860 KB |
Output is correct |
45 |
Correct |
197 ms |
21500 KB |
Output is correct |
46 |
Correct |
84 ms |
10104 KB |
Output is correct |
47 |
Correct |
80 ms |
10488 KB |
Output is correct |
48 |
Correct |
80 ms |
10136 KB |
Output is correct |
49 |
Correct |
394 ms |
25920 KB |
Output is correct |
50 |
Correct |
622 ms |
60916 KB |
Output is correct |
51 |
Correct |
532 ms |
60428 KB |
Output is correct |
52 |
Correct |
511 ms |
59112 KB |
Output is correct |
53 |
Correct |
186 ms |
22236 KB |
Output is correct |
54 |
Correct |
202 ms |
22268 KB |
Output is correct |
55 |
Correct |
514 ms |
57752 KB |
Output is correct |
56 |
Correct |
527 ms |
59752 KB |
Output is correct |
57 |
Correct |
197 ms |
22536 KB |
Output is correct |
58 |
Correct |
84 ms |
10104 KB |
Output is correct |
59 |
Correct |
79 ms |
10208 KB |
Output is correct |
60 |
Correct |
82 ms |
10236 KB |
Output is correct |
61 |
Correct |
339 ms |
25804 KB |
Output is correct |
62 |
Correct |
522 ms |
59712 KB |
Output is correct |
63 |
Correct |
507 ms |
59920 KB |
Output is correct |
64 |
Correct |
516 ms |
60256 KB |
Output is correct |
65 |
Correct |
83 ms |
10208 KB |
Output is correct |
66 |
Correct |
379 ms |
29040 KB |
Output is correct |
67 |
Correct |
544 ms |
59676 KB |
Output is correct |
68 |
Correct |
517 ms |
60084 KB |
Output is correct |
69 |
Correct |
524 ms |
58680 KB |
Output is correct |
70 |
Correct |
79 ms |
10140 KB |
Output is correct |
71 |
Correct |
79 ms |
10232 KB |
Output is correct |
72 |
Correct |
103 ms |
10024 KB |
Output is correct |
73 |
Correct |
366 ms |
26796 KB |
Output is correct |
74 |
Correct |
514 ms |
60124 KB |
Output is correct |
75 |
Correct |
503 ms |
58476 KB |
Output is correct |
76 |
Correct |
628 ms |
60088 KB |
Output is correct |
77 |
Correct |
506 ms |
60068 KB |
Output is correct |
78 |
Correct |
77 ms |
10228 KB |
Output is correct |
79 |
Correct |
79 ms |
10100 KB |
Output is correct |
80 |
Correct |
106 ms |
11128 KB |
Output is correct |
81 |
Correct |
186 ms |
21804 KB |
Output is correct |
82 |
Correct |
83 ms |
10000 KB |
Output is correct |
83 |
Correct |
81 ms |
10196 KB |
Output is correct |
84 |
Correct |
80 ms |
10004 KB |
Output is correct |
85 |
Correct |
354 ms |
27452 KB |
Output is correct |
86 |
Correct |
194 ms |
21848 KB |
Output is correct |
87 |
Correct |
175 ms |
22000 KB |
Output is correct |
88 |
Correct |
191 ms |
22292 KB |
Output is correct |
89 |
Correct |
181 ms |
22120 KB |
Output is correct |
90 |
Correct |
92 ms |
10144 KB |
Output is correct |
91 |
Correct |
78 ms |
10100 KB |
Output is correct |
92 |
Correct |
103 ms |
10624 KB |
Output is correct |
93 |
Correct |
128 ms |
15092 KB |
Output is correct |
94 |
Correct |
78 ms |
10240 KB |
Output is correct |
95 |
Correct |
77 ms |
10104 KB |
Output is correct |
96 |
Correct |
88 ms |
9976 KB |
Output is correct |
97 |
Correct |
117 ms |
12172 KB |
Output is correct |
98 |
Correct |
137 ms |
15236 KB |
Output is correct |
99 |
Correct |
136 ms |
15480 KB |
Output is correct |
100 |
Correct |
145 ms |
15480 KB |
Output is correct |
101 |
Correct |
146 ms |
16972 KB |
Output is correct |
102 |
Correct |
129 ms |
15356 KB |
Output is correct |
103 |
Correct |
141 ms |
15304 KB |
Output is correct |
104 |
Correct |
136 ms |
15240 KB |
Output is correct |
105 |
Correct |
134 ms |
15100 KB |
Output is correct |