Submission #379787

# Submission time Handle Problem Language Result Execution time Memory
379787 2021-03-19T09:56:55 Z abra_stone Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
296 ms 32236 KB
#include "supertrees.h"
#include <vector>
#define N 1005
using namespace std;

int n, gc, gr[N], pa[N], a[N][N], aa[N][N];
bool v[N];
vector<int> rt, ve;
vector<vector<int> > answer;

int uni(int p) {
	if (pa[p] == p) return p;
	else return pa[p] = uni(pa[p]);
}

void make_tree(int p) {
	int i;
	gr[p] = gc;
	for (i = 0; i < n; i++) {
		if (a[p][i] != 1 || gr[i]) continue;
		answer[p][i] = answer[i][p] = 1;
		pa[uni(i)] = uni(p);
		make_tree(i);
	}
}

void make_cy(int p) {
	int i;
	if (v[p]) return;
	v[p] = 1;
	ve.push_back(p);
	for (i = 0; i < rt.size(); i++) {
		int ne = rt[i];
		if (a[p][ne] == 2) make_cy(ne);
	}
}

int construct(std::vector<std::vector<int> > P) {
	n = P.size();
	int i, j;
	vector<int> t;
	t.clear();
	for (i = 0; i < n; i++) t.push_back(0);
	for (i = 0; i < n; i++) answer.push_back(t);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			a[i][j] = P[i][j];
			if (a[i][j] == 3) return 0;
		}
	}
	for (i = 0; i < n; i++) pa[i] = i;

	for (i = 0; i < n; i++) {
		if (!gr[i]) {
			gc++;
			rt.push_back(i);
			make_tree(i);
		}
	}

	for (i = 0; i < rt.size(); i++) {
		if (!v[rt[i]]) {
			ve.clear();
			make_cy(rt[i]);
			if (ve.size() == 2) return 0;
			for (i = 1; i < ve.size(); i++) {
				int t1 = ve[i - 1], t2 = ve[i];
				pa[uni(t1)] = uni(t2);
				answer[t1][t2] = answer[t2][t1] = 1;
			}
			if (ve.size() > 1) {
				int t1 = ve[ve.size() - 1], t2 = ve[0];
				pa[uni(t1)] = uni(t2);
				answer[t1][t2] = answer[t2][t1] = 1;
			}
		}
	}

	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			if (gr[i] == gr[j]) aa[i][j] = 1;
			else if (uni(i) == uni(j)) aa[i][j] = 2;
			else aa[i][j] = 0;
		}
	}
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			if (aa[i][j] != a[i][j]) return 0;
		}
	}
	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'void make_cy(int)':
supertrees.cpp:32:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |  for (i = 0; i < rt.size(); i++) {
      |              ~~^~~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:61:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |  for (i = 0; i < rt.size(); i++) {
      |              ~~^~~~~~~~~~~
supertrees.cpp:66:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |    for (i = 1; i < ve.size(); i++) {
      |                ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 11 ms 2796 KB Output is correct
7 Correct 244 ms 30188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 11 ms 2796 KB Output is correct
7 Correct 244 ms 30188 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 11 ms 2816 KB Output is correct
13 Correct 255 ms 30060 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 6 ms 2412 KB Output is correct
17 Correct 128 ms 20204 KB Output is correct
18 Correct 1 ms 496 KB Output is correct
19 Correct 0 ms 364 KB Output is correct
20 Correct 70 ms 9836 KB Output is correct
21 Correct 264 ms 29932 KB Output is correct
22 Correct 261 ms 29932 KB Output is correct
23 Correct 260 ms 30060 KB Output is correct
24 Correct 256 ms 29932 KB Output is correct
25 Correct 128 ms 20060 KB Output is correct
26 Correct 125 ms 20076 KB Output is correct
27 Correct 265 ms 30060 KB Output is correct
28 Correct 260 ms 30060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 12 ms 2924 KB Output is correct
9 Correct 258 ms 31980 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 16 ms 2924 KB Output is correct
13 Correct 255 ms 32108 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 7 ms 2412 KB Output is correct
17 Correct 137 ms 21996 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 67 ms 10220 KB Output is correct
22 Correct 258 ms 31980 KB Output is correct
23 Correct 269 ms 32108 KB Output is correct
24 Correct 291 ms 32236 KB Output is correct
25 Correct 111 ms 18080 KB Output is correct
26 Correct 126 ms 21996 KB Output is correct
27 Correct 258 ms 31980 KB Output is correct
28 Correct 296 ms 31980 KB Output is correct
29 Correct 118 ms 18028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 65 ms 9708 KB Output is correct
5 Correct 260 ms 29932 KB Output is correct
6 Correct 254 ms 30060 KB Output is correct
7 Correct 262 ms 30044 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 66 ms 9856 KB Output is correct
10 Correct 256 ms 29932 KB Output is correct
11 Correct 272 ms 30316 KB Output is correct
12 Correct 269 ms 30060 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 66 ms 9708 KB Output is correct
17 Correct 263 ms 30060 KB Output is correct
18 Correct 256 ms 29932 KB Output is correct
19 Correct 265 ms 30060 KB Output is correct
20 Correct 273 ms 29932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 11 ms 2796 KB Output is correct
7 Correct 244 ms 30188 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 11 ms 2816 KB Output is correct
13 Correct 255 ms 30060 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 6 ms 2412 KB Output is correct
17 Correct 128 ms 20204 KB Output is correct
18 Correct 1 ms 496 KB Output is correct
19 Correct 0 ms 364 KB Output is correct
20 Correct 70 ms 9836 KB Output is correct
21 Correct 264 ms 29932 KB Output is correct
22 Correct 261 ms 29932 KB Output is correct
23 Correct 260 ms 30060 KB Output is correct
24 Correct 256 ms 29932 KB Output is correct
25 Correct 128 ms 20060 KB Output is correct
26 Correct 125 ms 20076 KB Output is correct
27 Correct 265 ms 30060 KB Output is correct
28 Correct 260 ms 30060 KB Output is correct
29 Correct 0 ms 364 KB Output is correct
30 Correct 0 ms 364 KB Output is correct
31 Correct 0 ms 364 KB Output is correct
32 Correct 0 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 12 ms 2924 KB Output is correct
37 Correct 258 ms 31980 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 16 ms 2924 KB Output is correct
41 Correct 255 ms 32108 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 7 ms 2412 KB Output is correct
45 Correct 137 ms 21996 KB Output is correct
46 Correct 0 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 67 ms 10220 KB Output is correct
50 Correct 258 ms 31980 KB Output is correct
51 Correct 269 ms 32108 KB Output is correct
52 Correct 291 ms 32236 KB Output is correct
53 Correct 111 ms 18080 KB Output is correct
54 Correct 126 ms 21996 KB Output is correct
55 Correct 258 ms 31980 KB Output is correct
56 Correct 296 ms 31980 KB Output is correct
57 Correct 118 ms 18028 KB Output is correct
58 Correct 1 ms 364 KB Output is correct
59 Correct 0 ms 364 KB Output is correct
60 Correct 6 ms 2412 KB Output is correct
61 Correct 123 ms 22124 KB Output is correct
62 Correct 1 ms 364 KB Output is correct
63 Correct 1 ms 364 KB Output is correct
64 Correct 1 ms 364 KB Output is correct
65 Correct 68 ms 10364 KB Output is correct
66 Correct 128 ms 21996 KB Output is correct
67 Correct 123 ms 21996 KB Output is correct
68 Correct 123 ms 22124 KB Output is correct
69 Correct 115 ms 18156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 11 ms 2796 KB Output is correct
7 Correct 244 ms 30188 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 11 ms 2816 KB Output is correct
13 Correct 255 ms 30060 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 6 ms 2412 KB Output is correct
17 Correct 128 ms 20204 KB Output is correct
18 Correct 1 ms 496 KB Output is correct
19 Correct 0 ms 364 KB Output is correct
20 Correct 70 ms 9836 KB Output is correct
21 Correct 264 ms 29932 KB Output is correct
22 Correct 261 ms 29932 KB Output is correct
23 Correct 260 ms 30060 KB Output is correct
24 Correct 256 ms 29932 KB Output is correct
25 Correct 128 ms 20060 KB Output is correct
26 Correct 125 ms 20076 KB Output is correct
27 Correct 265 ms 30060 KB Output is correct
28 Correct 260 ms 30060 KB Output is correct
29 Correct 0 ms 364 KB Output is correct
30 Correct 0 ms 364 KB Output is correct
31 Correct 0 ms 364 KB Output is correct
32 Correct 0 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 12 ms 2924 KB Output is correct
37 Correct 258 ms 31980 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 16 ms 2924 KB Output is correct
41 Correct 255 ms 32108 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 7 ms 2412 KB Output is correct
45 Correct 137 ms 21996 KB Output is correct
46 Correct 0 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 67 ms 10220 KB Output is correct
50 Correct 258 ms 31980 KB Output is correct
51 Correct 269 ms 32108 KB Output is correct
52 Correct 291 ms 32236 KB Output is correct
53 Correct 111 ms 18080 KB Output is correct
54 Correct 126 ms 21996 KB Output is correct
55 Correct 258 ms 31980 KB Output is correct
56 Correct 296 ms 31980 KB Output is correct
57 Correct 118 ms 18028 KB Output is correct
58 Correct 0 ms 364 KB Output is correct
59 Correct 0 ms 364 KB Output is correct
60 Correct 1 ms 384 KB Output is correct
61 Correct 65 ms 9708 KB Output is correct
62 Correct 260 ms 29932 KB Output is correct
63 Correct 254 ms 30060 KB Output is correct
64 Correct 262 ms 30044 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Correct 66 ms 9856 KB Output is correct
67 Correct 256 ms 29932 KB Output is correct
68 Correct 272 ms 30316 KB Output is correct
69 Correct 269 ms 30060 KB Output is correct
70 Correct 1 ms 364 KB Output is correct
71 Correct 1 ms 364 KB Output is correct
72 Correct 1 ms 364 KB Output is correct
73 Correct 66 ms 9708 KB Output is correct
74 Correct 263 ms 30060 KB Output is correct
75 Correct 256 ms 29932 KB Output is correct
76 Correct 265 ms 30060 KB Output is correct
77 Correct 273 ms 29932 KB Output is correct
78 Correct 1 ms 364 KB Output is correct
79 Correct 0 ms 364 KB Output is correct
80 Correct 6 ms 2412 KB Output is correct
81 Correct 123 ms 22124 KB Output is correct
82 Correct 1 ms 364 KB Output is correct
83 Correct 1 ms 364 KB Output is correct
84 Correct 1 ms 364 KB Output is correct
85 Correct 68 ms 10364 KB Output is correct
86 Correct 128 ms 21996 KB Output is correct
87 Correct 123 ms 21996 KB Output is correct
88 Correct 123 ms 22124 KB Output is correct
89 Correct 115 ms 18156 KB Output is correct
90 Correct 1 ms 364 KB Output is correct
91 Correct 1 ms 364 KB Output is correct
92 Correct 5 ms 876 KB Output is correct
93 Correct 111 ms 14316 KB Output is correct
94 Correct 1 ms 364 KB Output is correct
95 Correct 1 ms 364 KB Output is correct
96 Correct 1 ms 364 KB Output is correct
97 Correct 27 ms 3948 KB Output is correct
98 Correct 108 ms 14316 KB Output is correct
99 Correct 131 ms 14700 KB Output is correct
100 Correct 114 ms 14444 KB Output is correct
101 Correct 113 ms 15468 KB Output is correct
102 Correct 118 ms 14188 KB Output is correct
103 Correct 125 ms 14216 KB Output is correct
104 Correct 109 ms 14188 KB Output is correct
105 Correct 112 ms 14188 KB Output is correct