Submission #300442

# Submission time Handle Problem Language Result Execution time Memory
300442 2020-09-17T07:17:47 Z faustaadp Connecting Supertrees (IOI20_supertrees) C++17
96 / 100
283 ms 26232 KB
#include "supertrees.h"
#include <vector>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const ll NN = 1e3 + 5;
ll n, bisa = 1, p[NN], x[NN], kel[NN], ket[NN];
std::vector<std::vector<int>> answer;
vector<ll> v[NN];
std::vector<std::vector<int>> px;
ll car(ll pos)
{
	if(p[pos] == pos)
		return pos;
	else
		return p[pos] = car(p[pos]);
}
int construct(std::vector<std::vector<int>> pt) {
	px = pt;
	n = px.size();
	for (int i = 0; i < n; i++) {
		std::vector<int> row;
		row.resize(n, 0);
		answer.push_back(row);
	}
	for (int i = 0; i < n; i++) 
		p[i] = i;
	for (int i = 0; i < n; i++) 
		for (int j = i + 1; j < n; j++) 
			if(px[i][j])
				p[car(i)] = car(j); 
	for (int i = 0; i < n; i++) 
		v[car(i)].pb(i);
	for (int i = 0; i < n; i++) 
	{
		if(!bisa)
			break;
		ll sz = v[i].size();
		x[0] = 0;
		x[1] = 0;
		x[2] = 0;
		x[3] = 0;
		for(ll j = 0; j < sz; j++)
			for(ll k = j + 1; k < sz; k++)
				x[px[v[i][j]][v[i][k]]] = 1;
		if(x[0] + x[1] + x[2] + x[3] == 0) 
			continue;
		else
		if(x[0])
			bisa = 0;
		else
		if(x[2] == 1 && x[3] == 1)
			bisa = 0;
		else
		if(x[1] == 1 && x[2] == 0 && x[3] == 0)
		{
			for(ll j = 1; j < sz; j++)
			{
				answer[v[i][j - 1]][v[i][j]] = 1;
				answer[v[i][j]][v[i][j - 1]] = 1;
			}
		}
		else
		if(x[2] == 1)
		{
			ll te = 0;
			for(ll j = 0; j < sz; j++)
			{
				if(kel[v[i][j]])
					continue;
				te++;
				kel[v[i][j]] = te;
				ket[te] = v[i][j];
				// cout << te << " " << ket[te] << "_\n"
				for(ll k = 0; k < sz; k++)
				{
					if(j == k)
						continue;
					if(px[v[i][j]][v[i][k]] == 1)
					{
						kel[v[i][k]] = te;
						// cout << v[i][j] << " " << v[i][k] << "_\n";
						answer[v[i][j]][v[i][k]] = 1;
						answer[v[i][k]][v[i][j]] = 1;
					}
				}
			}
			for(ll j = 0; j < sz; j++)
				for(ll k = j + 1; k < sz; k++)
				{
					if(px[v[i][j]][v[i][k]] == 1 && kel[v[i][j]] != kel[v[i][k]])
						bisa = 0;
					if(px[v[i][j]][v[i][k]] != 1 && kel[v[i][j]] == kel[v[i][k]])
						bisa = 0;
				}
			if(te <= 2)
				bisa = 0;
			if(!bisa)
				break;
			for(ll j = 1; j < te; j++)
			{
				// cout << ket[j] << " " << ket[j + 1] << "_\n";
				answer[ket[j]][ket[j + 1]] = 1;
				answer[ket[j + 1]][ket[j]] = 1;
			}
			answer[ket[te]][ket[1]] = 1;
			answer[ket[1]][ket[te]] = 1;
		}
		else
		if(x[3] == 1)
		{
			ll te = 0;
			for(ll j = 0; j < sz; j++)
			{
				if(kel[v[i][j]])
					continue;
				te++;
				kel[v[i][j]] = te;
				ket[te] = v[i][j];
				// cout << te << " " << ket[te] << "_\n"
				for(ll k = 0; k < sz; k++)
				{
					if(j == k)
						continue;
					if(px[v[i][j]][v[i][k]] == 1)
					{
						kel[v[i][k]] = te;
						// cout << v[i][j] << " " << v[i][k] << "_\n";
						answer[v[i][j]][v[i][k]] = 1;
						answer[v[i][k]][v[i][j]] = 1;
					}
				}
			}
			if(te <= 5)
				bisa = 0;
			for(ll j = 0; j < sz; j++)
				for(ll k = j + 1; k < sz; k++)
				{
					if(px[v[i][j]][v[i][k]] == 1 && kel[v[i][j]] != kel[v[i][k]])
						bisa = 0;
					if(px[v[i][j]][v[i][k]] != 1 && kel[v[i][j]] == kel[v[i][k]])
						bisa = 0;
				}
			if(!bisa)
				break;
			for(ll j = 1; j < te; j++)
			{
				// cout << ket[j] << " " << ket[j + 1] << "_\n";
				answer[ket[j]][ket[j + 1]] = 1;
				answer[ket[j + 1]][ket[j]] = 1;
			}
			answer[ket[te]][ket[1]] = 1;
			answer[ket[1]][ket[te]] = 1;
			answer[ket[te]][ket[2]] = 1;
			answer[ket[2]][ket[te]] = 1;
		}
	}
	if(!bisa)return 0;
	build(answer);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 288 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 13 ms 1408 KB Output is correct
7 Correct 283 ms 26104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 288 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 13 ms 1408 KB Output is correct
7 Correct 283 ms 26104 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 10 ms 1408 KB Output is correct
13 Correct 252 ms 26104 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 5 ms 1024 KB Output is correct
17 Correct 131 ms 16120 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 62 ms 6908 KB Output is correct
21 Correct 265 ms 26104 KB Output is correct
22 Correct 253 ms 26104 KB Output is correct
23 Correct 260 ms 26104 KB Output is correct
24 Correct 245 ms 26104 KB Output is correct
25 Correct 171 ms 16120 KB Output is correct
26 Correct 118 ms 16112 KB Output is correct
27 Correct 273 ms 26104 KB Output is correct
28 Correct 252 ms 26104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 288 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 10 ms 1408 KB Output is correct
9 Correct 247 ms 26104 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 11 ms 1408 KB Output is correct
13 Correct 261 ms 26104 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 5 ms 1024 KB Output is correct
17 Correct 119 ms 16120 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 64 ms 6908 KB Output is correct
22 Correct 249 ms 26232 KB Output is correct
23 Correct 243 ms 26104 KB Output is correct
24 Correct 262 ms 26232 KB Output is correct
25 Correct 109 ms 16120 KB Output is correct
26 Correct 109 ms 16120 KB Output is correct
27 Correct 244 ms 26104 KB Output is correct
28 Correct 260 ms 26108 KB Output is correct
29 Correct 105 ms 16248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 62 ms 6904 KB Output is correct
5 Correct 252 ms 26104 KB Output is correct
6 Correct 242 ms 26104 KB Output is correct
7 Correct 257 ms 26104 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 67 ms 6904 KB Output is correct
10 Correct 256 ms 26104 KB Output is correct
11 Correct 244 ms 26092 KB Output is correct
12 Correct 262 ms 26104 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 63 ms 6904 KB Output is correct
17 Correct 252 ms 26156 KB Output is correct
18 Correct 256 ms 26104 KB Output is correct
19 Correct 248 ms 26104 KB Output is correct
20 Correct 248 ms 26104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 288 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 13 ms 1408 KB Output is correct
7 Correct 283 ms 26104 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 10 ms 1408 KB Output is correct
13 Correct 252 ms 26104 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 5 ms 1024 KB Output is correct
17 Correct 131 ms 16120 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 62 ms 6908 KB Output is correct
21 Correct 265 ms 26104 KB Output is correct
22 Correct 253 ms 26104 KB Output is correct
23 Correct 260 ms 26104 KB Output is correct
24 Correct 245 ms 26104 KB Output is correct
25 Correct 171 ms 16120 KB Output is correct
26 Correct 118 ms 16112 KB Output is correct
27 Correct 273 ms 26104 KB Output is correct
28 Correct 252 ms 26104 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 288 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 10 ms 1408 KB Output is correct
37 Correct 247 ms 26104 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 11 ms 1408 KB Output is correct
41 Correct 261 ms 26104 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 5 ms 1024 KB Output is correct
45 Correct 119 ms 16120 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 64 ms 6908 KB Output is correct
50 Correct 249 ms 26232 KB Output is correct
51 Correct 243 ms 26104 KB Output is correct
52 Correct 262 ms 26232 KB Output is correct
53 Correct 109 ms 16120 KB Output is correct
54 Correct 109 ms 16120 KB Output is correct
55 Correct 244 ms 26104 KB Output is correct
56 Correct 260 ms 26108 KB Output is correct
57 Correct 105 ms 16248 KB Output is correct
58 Correct 1 ms 384 KB Output is correct
59 Correct 1 ms 384 KB Output is correct
60 Correct 5 ms 1024 KB Output is correct
61 Correct 122 ms 16368 KB Output is correct
62 Correct 1 ms 384 KB Output is correct
63 Correct 1 ms 384 KB Output is correct
64 Correct 1 ms 384 KB Output is correct
65 Correct 63 ms 6904 KB Output is correct
66 Correct 108 ms 16120 KB Output is correct
67 Correct 109 ms 16120 KB Output is correct
68 Correct 136 ms 16120 KB Output is correct
69 Correct 105 ms 16120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 288 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 13 ms 1408 KB Output is correct
7 Correct 283 ms 26104 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 10 ms 1408 KB Output is correct
13 Correct 252 ms 26104 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 5 ms 1024 KB Output is correct
17 Correct 131 ms 16120 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 62 ms 6908 KB Output is correct
21 Correct 265 ms 26104 KB Output is correct
22 Correct 253 ms 26104 KB Output is correct
23 Correct 260 ms 26104 KB Output is correct
24 Correct 245 ms 26104 KB Output is correct
25 Correct 171 ms 16120 KB Output is correct
26 Correct 118 ms 16112 KB Output is correct
27 Correct 273 ms 26104 KB Output is correct
28 Correct 252 ms 26104 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 288 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 10 ms 1408 KB Output is correct
37 Correct 247 ms 26104 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 11 ms 1408 KB Output is correct
41 Correct 261 ms 26104 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 5 ms 1024 KB Output is correct
45 Correct 119 ms 16120 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 64 ms 6908 KB Output is correct
50 Correct 249 ms 26232 KB Output is correct
51 Correct 243 ms 26104 KB Output is correct
52 Correct 262 ms 26232 KB Output is correct
53 Correct 109 ms 16120 KB Output is correct
54 Correct 109 ms 16120 KB Output is correct
55 Correct 244 ms 26104 KB Output is correct
56 Correct 260 ms 26108 KB Output is correct
57 Correct 105 ms 16248 KB Output is correct
58 Correct 1 ms 384 KB Output is correct
59 Correct 1 ms 384 KB Output is correct
60 Correct 1 ms 384 KB Output is correct
61 Correct 62 ms 6904 KB Output is correct
62 Correct 252 ms 26104 KB Output is correct
63 Correct 242 ms 26104 KB Output is correct
64 Correct 257 ms 26104 KB Output is correct
65 Correct 1 ms 384 KB Output is correct
66 Correct 67 ms 6904 KB Output is correct
67 Correct 256 ms 26104 KB Output is correct
68 Correct 244 ms 26092 KB Output is correct
69 Correct 262 ms 26104 KB Output is correct
70 Correct 1 ms 384 KB Output is correct
71 Correct 1 ms 384 KB Output is correct
72 Correct 1 ms 384 KB Output is correct
73 Correct 63 ms 6904 KB Output is correct
74 Correct 252 ms 26156 KB Output is correct
75 Correct 256 ms 26104 KB Output is correct
76 Correct 248 ms 26104 KB Output is correct
77 Correct 248 ms 26104 KB Output is correct
78 Correct 1 ms 384 KB Output is correct
79 Correct 1 ms 384 KB Output is correct
80 Correct 5 ms 1024 KB Output is correct
81 Correct 122 ms 16368 KB Output is correct
82 Correct 1 ms 384 KB Output is correct
83 Correct 1 ms 384 KB Output is correct
84 Correct 1 ms 384 KB Output is correct
85 Correct 63 ms 6904 KB Output is correct
86 Correct 108 ms 16120 KB Output is correct
87 Correct 109 ms 16120 KB Output is correct
88 Correct 136 ms 16120 KB Output is correct
89 Correct 105 ms 16120 KB Output is correct
90 Correct 1 ms 384 KB Output is correct
91 Correct 1 ms 384 KB Output is correct
92 Correct 5 ms 1024 KB Output is correct
93 Correct 119 ms 16248 KB Output is correct
94 Correct 1 ms 384 KB Output is correct
95 Correct 1 ms 384 KB Output is correct
96 Correct 1 ms 384 KB Output is correct
97 Correct 28 ms 4352 KB Output is correct
98 Correct 107 ms 16248 KB Output is correct
99 Correct 113 ms 16120 KB Output is correct
100 Correct 117 ms 16120 KB Output is correct
101 Correct 113 ms 16248 KB Output is correct
102 Incorrect 258 ms 26104 KB Answer gives possible 1 while actual possible 0
103 Halted 0 ms 0 KB -