Submission #300162

# Submission time Handle Problem Language Result Execution time Memory
300162 2020-09-16T22:01:19 Z model_code Connecting Supertrees (IOI20_supertrees) Java 11
96 / 100
549 ms 61620 KB
// yanhao-st5
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<>());

		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;
	}
}
# Verdict Execution time Memory Grader output
1 Correct 89 ms 10336 KB Output is correct
2 Correct 83 ms 10136 KB Output is correct
3 Correct 86 ms 10192 KB Output is correct
4 Correct 97 ms 10256 KB Output is correct
5 Correct 85 ms 10060 KB Output is correct
6 Correct 209 ms 16840 KB Output is correct
7 Correct 458 ms 57464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 10336 KB Output is correct
2 Correct 83 ms 10136 KB Output is correct
3 Correct 86 ms 10192 KB Output is correct
4 Correct 97 ms 10256 KB Output is correct
5 Correct 85 ms 10060 KB Output is correct
6 Correct 209 ms 16840 KB Output is correct
7 Correct 458 ms 57464 KB Output is correct
8 Correct 80 ms 10236 KB Output is correct
9 Correct 78 ms 10340 KB Output is correct
10 Correct 79 ms 10216 KB Output is correct
11 Correct 104 ms 10216 KB Output is correct
12 Correct 215 ms 16060 KB Output is correct
13 Correct 544 ms 59664 KB Output is correct
14 Correct 76 ms 10104 KB Output is correct
15 Correct 80 ms 10112 KB Output is correct
16 Correct 97 ms 10920 KB Output is correct
17 Correct 167 ms 21540 KB Output is correct
18 Correct 81 ms 10112 KB Output is correct
19 Correct 82 ms 10464 KB Output is correct
20 Correct 331 ms 29544 KB Output is correct
21 Correct 508 ms 59740 KB Output is correct
22 Correct 492 ms 57472 KB Output is correct
23 Correct 508 ms 57616 KB Output is correct
24 Correct 476 ms 58724 KB Output is correct
25 Correct 193 ms 22068 KB Output is correct
26 Correct 203 ms 21940 KB Output is correct
27 Correct 549 ms 61620 KB Output is correct
28 Correct 481 ms 57440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 10176 KB Output is correct
2 Correct 81 ms 10160 KB Output is correct
3 Correct 84 ms 10236 KB Output is correct
4 Correct 84 ms 10280 KB Output is correct
5 Correct 84 ms 10236 KB Output is correct
6 Correct 84 ms 10252 KB Output is correct
7 Correct 77 ms 9984 KB Output is correct
8 Correct 194 ms 16116 KB Output is correct
9 Correct 509 ms 59944 KB Output is correct
10 Correct 75 ms 10344 KB Output is correct
11 Correct 80 ms 10232 KB Output is correct
12 Correct 186 ms 16036 KB Output is correct
13 Correct 468 ms 57572 KB Output is correct
14 Correct 78 ms 10100 KB Output is correct
15 Correct 80 ms 10340 KB Output is correct
16 Correct 100 ms 10984 KB Output is correct
17 Correct 166 ms 22120 KB Output is correct
18 Correct 78 ms 10100 KB Output is correct
19 Correct 79 ms 10228 KB Output is correct
20 Correct 79 ms 10104 KB Output is correct
21 Correct 354 ms 27216 KB Output is correct
22 Correct 528 ms 61112 KB Output is correct
23 Correct 520 ms 59344 KB Output is correct
24 Correct 504 ms 60964 KB Output is correct
25 Correct 183 ms 22168 KB Output is correct
26 Correct 180 ms 22080 KB Output is correct
27 Correct 523 ms 59320 KB Output is correct
28 Correct 517 ms 59276 KB Output is correct
29 Correct 175 ms 22284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 10316 KB Output is correct
2 Correct 80 ms 10216 KB Output is correct
3 Correct 82 ms 10360 KB Output is correct
4 Correct 362 ms 26144 KB Output is correct
5 Correct 467 ms 58616 KB Output is correct
6 Correct 501 ms 58600 KB Output is correct
7 Correct 468 ms 57512 KB Output is correct
8 Correct 79 ms 10104 KB Output is correct
9 Correct 340 ms 26388 KB Output is correct
10 Correct 504 ms 57996 KB Output is correct
11 Correct 488 ms 59360 KB Output is correct
12 Correct 545 ms 61536 KB Output is correct
13 Correct 77 ms 10216 KB Output is correct
14 Correct 81 ms 10344 KB Output is correct
15 Correct 79 ms 10344 KB Output is correct
16 Correct 399 ms 30580 KB Output is correct
17 Correct 498 ms 61164 KB Output is correct
18 Correct 487 ms 57516 KB Output is correct
19 Correct 479 ms 58176 KB Output is correct
20 Correct 527 ms 60540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 10336 KB Output is correct
2 Correct 83 ms 10136 KB Output is correct
3 Correct 86 ms 10192 KB Output is correct
4 Correct 97 ms 10256 KB Output is correct
5 Correct 85 ms 10060 KB Output is correct
6 Correct 209 ms 16840 KB Output is correct
7 Correct 458 ms 57464 KB Output is correct
8 Correct 80 ms 10236 KB Output is correct
9 Correct 78 ms 10340 KB Output is correct
10 Correct 79 ms 10216 KB Output is correct
11 Correct 104 ms 10216 KB Output is correct
12 Correct 215 ms 16060 KB Output is correct
13 Correct 544 ms 59664 KB Output is correct
14 Correct 76 ms 10104 KB Output is correct
15 Correct 80 ms 10112 KB Output is correct
16 Correct 97 ms 10920 KB Output is correct
17 Correct 167 ms 21540 KB Output is correct
18 Correct 81 ms 10112 KB Output is correct
19 Correct 82 ms 10464 KB Output is correct
20 Correct 331 ms 29544 KB Output is correct
21 Correct 508 ms 59740 KB Output is correct
22 Correct 492 ms 57472 KB Output is correct
23 Correct 508 ms 57616 KB Output is correct
24 Correct 476 ms 58724 KB Output is correct
25 Correct 193 ms 22068 KB Output is correct
26 Correct 203 ms 21940 KB Output is correct
27 Correct 549 ms 61620 KB Output is correct
28 Correct 481 ms 57440 KB Output is correct
29 Correct 83 ms 10176 KB Output is correct
30 Correct 81 ms 10160 KB Output is correct
31 Correct 84 ms 10236 KB Output is correct
32 Correct 84 ms 10280 KB Output is correct
33 Correct 84 ms 10236 KB Output is correct
34 Correct 84 ms 10252 KB Output is correct
35 Correct 77 ms 9984 KB Output is correct
36 Correct 194 ms 16116 KB Output is correct
37 Correct 509 ms 59944 KB Output is correct
38 Correct 75 ms 10344 KB Output is correct
39 Correct 80 ms 10232 KB Output is correct
40 Correct 186 ms 16036 KB Output is correct
41 Correct 468 ms 57572 KB Output is correct
42 Correct 78 ms 10100 KB Output is correct
43 Correct 80 ms 10340 KB Output is correct
44 Correct 100 ms 10984 KB Output is correct
45 Correct 166 ms 22120 KB Output is correct
46 Correct 78 ms 10100 KB Output is correct
47 Correct 79 ms 10228 KB Output is correct
48 Correct 79 ms 10104 KB Output is correct
49 Correct 354 ms 27216 KB Output is correct
50 Correct 528 ms 61112 KB Output is correct
51 Correct 520 ms 59344 KB Output is correct
52 Correct 504 ms 60964 KB Output is correct
53 Correct 183 ms 22168 KB Output is correct
54 Correct 180 ms 22080 KB Output is correct
55 Correct 523 ms 59320 KB Output is correct
56 Correct 517 ms 59276 KB Output is correct
57 Correct 175 ms 22284 KB Output is correct
58 Correct 80 ms 10216 KB Output is correct
59 Correct 77 ms 10344 KB Output is correct
60 Correct 97 ms 11000 KB Output is correct
61 Correct 161 ms 21492 KB Output is correct
62 Correct 80 ms 10360 KB Output is correct
63 Correct 84 ms 10360 KB Output is correct
64 Correct 83 ms 10280 KB Output is correct
65 Correct 343 ms 26884 KB Output is correct
66 Correct 175 ms 21972 KB Output is correct
67 Correct 193 ms 22168 KB Output is correct
68 Correct 194 ms 22288 KB Output is correct
69 Correct 174 ms 22184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 10336 KB Output is correct
2 Correct 83 ms 10136 KB Output is correct
3 Correct 86 ms 10192 KB Output is correct
4 Correct 97 ms 10256 KB Output is correct
5 Correct 85 ms 10060 KB Output is correct
6 Correct 209 ms 16840 KB Output is correct
7 Correct 458 ms 57464 KB Output is correct
8 Correct 80 ms 10236 KB Output is correct
9 Correct 78 ms 10340 KB Output is correct
10 Correct 79 ms 10216 KB Output is correct
11 Correct 104 ms 10216 KB Output is correct
12 Correct 215 ms 16060 KB Output is correct
13 Correct 544 ms 59664 KB Output is correct
14 Correct 76 ms 10104 KB Output is correct
15 Correct 80 ms 10112 KB Output is correct
16 Correct 97 ms 10920 KB Output is correct
17 Correct 167 ms 21540 KB Output is correct
18 Correct 81 ms 10112 KB Output is correct
19 Correct 82 ms 10464 KB Output is correct
20 Correct 331 ms 29544 KB Output is correct
21 Correct 508 ms 59740 KB Output is correct
22 Correct 492 ms 57472 KB Output is correct
23 Correct 508 ms 57616 KB Output is correct
24 Correct 476 ms 58724 KB Output is correct
25 Correct 193 ms 22068 KB Output is correct
26 Correct 203 ms 21940 KB Output is correct
27 Correct 549 ms 61620 KB Output is correct
28 Correct 481 ms 57440 KB Output is correct
29 Correct 83 ms 10176 KB Output is correct
30 Correct 81 ms 10160 KB Output is correct
31 Correct 84 ms 10236 KB Output is correct
32 Correct 84 ms 10280 KB Output is correct
33 Correct 84 ms 10236 KB Output is correct
34 Correct 84 ms 10252 KB Output is correct
35 Correct 77 ms 9984 KB Output is correct
36 Correct 194 ms 16116 KB Output is correct
37 Correct 509 ms 59944 KB Output is correct
38 Correct 75 ms 10344 KB Output is correct
39 Correct 80 ms 10232 KB Output is correct
40 Correct 186 ms 16036 KB Output is correct
41 Correct 468 ms 57572 KB Output is correct
42 Correct 78 ms 10100 KB Output is correct
43 Correct 80 ms 10340 KB Output is correct
44 Correct 100 ms 10984 KB Output is correct
45 Correct 166 ms 22120 KB Output is correct
46 Correct 78 ms 10100 KB Output is correct
47 Correct 79 ms 10228 KB Output is correct
48 Correct 79 ms 10104 KB Output is correct
49 Correct 354 ms 27216 KB Output is correct
50 Correct 528 ms 61112 KB Output is correct
51 Correct 520 ms 59344 KB Output is correct
52 Correct 504 ms 60964 KB Output is correct
53 Correct 183 ms 22168 KB Output is correct
54 Correct 180 ms 22080 KB Output is correct
55 Correct 523 ms 59320 KB Output is correct
56 Correct 517 ms 59276 KB Output is correct
57 Correct 175 ms 22284 KB Output is correct
58 Correct 87 ms 10316 KB Output is correct
59 Correct 80 ms 10216 KB Output is correct
60 Correct 82 ms 10360 KB Output is correct
61 Correct 362 ms 26144 KB Output is correct
62 Correct 467 ms 58616 KB Output is correct
63 Correct 501 ms 58600 KB Output is correct
64 Correct 468 ms 57512 KB Output is correct
65 Correct 79 ms 10104 KB Output is correct
66 Correct 340 ms 26388 KB Output is correct
67 Correct 504 ms 57996 KB Output is correct
68 Correct 488 ms 59360 KB Output is correct
69 Correct 545 ms 61536 KB Output is correct
70 Correct 77 ms 10216 KB Output is correct
71 Correct 81 ms 10344 KB Output is correct
72 Correct 79 ms 10344 KB Output is correct
73 Correct 399 ms 30580 KB Output is correct
74 Correct 498 ms 61164 KB Output is correct
75 Correct 487 ms 57516 KB Output is correct
76 Correct 479 ms 58176 KB Output is correct
77 Correct 527 ms 60540 KB Output is correct
78 Correct 80 ms 10216 KB Output is correct
79 Correct 77 ms 10344 KB Output is correct
80 Correct 97 ms 11000 KB Output is correct
81 Correct 161 ms 21492 KB Output is correct
82 Correct 80 ms 10360 KB Output is correct
83 Correct 84 ms 10360 KB Output is correct
84 Correct 83 ms 10280 KB Output is correct
85 Correct 343 ms 26884 KB Output is correct
86 Correct 175 ms 21972 KB Output is correct
87 Correct 193 ms 22168 KB Output is correct
88 Correct 194 ms 22288 KB Output is correct
89 Correct 174 ms 22184 KB Output is correct
90 Correct 81 ms 10360 KB Output is correct
91 Correct 78 ms 10344 KB Output is correct
92 Correct 94 ms 10996 KB Output is correct
93 Correct 161 ms 21492 KB Output is correct
94 Correct 77 ms 10280 KB Output is correct
95 Correct 77 ms 10228 KB Output is correct
96 Incorrect 77 ms 10232 KB Answer gives possible 1 while actual possible 0
97 Halted 0 ms 0 KB -