Submission #952782

# Submission time Handle Problem Language Result Execution time Memory
952782 2024-03-24T19:27:42 Z emad234 Connecting Supertrees (IOI20_supertrees) C++17
96 / 100
490 ms 73040 KB
#include "supertrees.h"
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define pii pair<ll, ll>
const ll mod = 1e9 + 7;
const ll mxN = 1e6 + 5;
using namespace std;

int dsu[mxN];
int find(int x) { return dsu[x] == x ? x : dsu[x] = find(dsu[x]); }
void merge(int a, int b) { dsu[find(b)] = find(a); }
int construct(std::vector<std::vector<int>> p)
{
	vector<vector<int>> b;
	int n = p.size(), m = p.size();
	b.resize(n);
	for (int i = 0; i < n; i++)
		dsu[i] = i;
	for (int i = 0; i < n; i++)
		b[i].resize(m);
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (i == j)
				continue;
			if (p[i][j] == 1)
			{
				if (find(i) != find(j))
				{
					merge(i, j);
					b[i][j] = 1;
					b[j][i] = 1;
				}
			}
		}
	}
	vector<vector<int>> ty;
	vector<set<int>> v;
	v.resize(n);
	ty.resize(n);
	for (int i = 0; i < n; i++)
	{
		ty[i].resize(n);
		for (int j = 0; j < m; j++)
		{
			ty[i][j] = -1;
		}
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (i == j)
				continue;
			if (find(i) == find(j))
			{
				if (p[i][j] != 1)
					return 0;
			}
			else
			{
				if (ty[find(i)][find(j)] != -1 && p[i][j] != ty[find(i)][find(j)])
					return 0;
				if (p[i][j] == 2)
				{
					v[find(i)].insert(find(j));
					v[find(j)].insert(find(i));
				}
				ty[find(i)][find(j)] = p[i][j];
			}
		}
	}
	vector<bool> vis(n);
	for (int i = 0; i < n; i++)
	{
		vector<bool>fnd(n);
		int prv = -1;
		if (vis[i])
			continue;
		if (v[i].size() == 1)
			return 0;
		v[i].insert(i);
		for(auto x : v[i]){
			fnd[x] = 1;
			for(auto y : v[x]){
				fnd[y] = 1;
			}
		}
		for (auto x : v[i])
		{
			for (int j = 0; j < n; j++)
			{
				if (x == j)
					continue;
				if (fnd[j] && p[x][j] != 2)
					return 0;
			}
			vis[x] = 1;
			if (prv != -1)
			{
				b[x][prv] = 1;
				b[prv][x] = 1;
			}
			prv = x;
		}
		if (v[i].size() >= 2)
		{
			b[*v[i].begin()][*v[i].rbegin()] = 1;
			b[*v[i].rbegin()][*v[i].begin()] = 1;
		}
	}
	build(b);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1376 KB Output is correct
7 Correct 150 ms 26116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1376 KB Output is correct
7 Correct 150 ms 26116 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1372 KB Output is correct
13 Correct 156 ms 25996 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 4 ms 860 KB Output is correct
17 Correct 69 ms 16160 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 40 ms 6880 KB Output is correct
21 Correct 163 ms 26196 KB Output is correct
22 Correct 156 ms 26192 KB Output is correct
23 Correct 160 ms 26124 KB Output is correct
24 Correct 156 ms 26084 KB Output is correct
25 Correct 61 ms 16212 KB Output is correct
26 Correct 60 ms 16212 KB Output is correct
27 Correct 161 ms 26104 KB Output is correct
28 Correct 153 ms 26128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 7 ms 1372 KB Output is correct
9 Correct 155 ms 26076 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 12 ms 3160 KB Output is correct
13 Correct 490 ms 73040 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 6 ms 2036 KB Output is correct
17 Correct 250 ms 39708 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 41 ms 7064 KB Output is correct
22 Correct 186 ms 30632 KB Output is correct
23 Correct 179 ms 26192 KB Output is correct
24 Correct 291 ms 49564 KB Output is correct
25 Correct 65 ms 16160 KB Output is correct
26 Correct 85 ms 20816 KB Output is correct
27 Correct 156 ms 28244 KB Output is correct
28 Correct 308 ms 51536 KB Output is correct
29 Correct 70 ms 18080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 40 ms 6792 KB Output is correct
5 Correct 164 ms 26152 KB Output is correct
6 Correct 158 ms 26140 KB Output is correct
7 Correct 159 ms 26148 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 39 ms 7252 KB Output is correct
10 Correct 173 ms 30700 KB Output is correct
11 Correct 148 ms 26404 KB Output is correct
12 Correct 293 ms 49476 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 40 ms 6868 KB Output is correct
17 Correct 171 ms 30820 KB Output is correct
18 Correct 169 ms 27888 KB Output is correct
19 Correct 161 ms 27060 KB Output is correct
20 Correct 157 ms 26132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1376 KB Output is correct
7 Correct 150 ms 26116 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1372 KB Output is correct
13 Correct 156 ms 25996 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 4 ms 860 KB Output is correct
17 Correct 69 ms 16160 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 40 ms 6880 KB Output is correct
21 Correct 163 ms 26196 KB Output is correct
22 Correct 156 ms 26192 KB Output is correct
23 Correct 160 ms 26124 KB Output is correct
24 Correct 156 ms 26084 KB Output is correct
25 Correct 61 ms 16212 KB Output is correct
26 Correct 60 ms 16212 KB Output is correct
27 Correct 161 ms 26104 KB Output is correct
28 Correct 153 ms 26128 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 7 ms 1372 KB Output is correct
37 Correct 155 ms 26076 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 12 ms 3160 KB Output is correct
41 Correct 490 ms 73040 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 6 ms 2036 KB Output is correct
45 Correct 250 ms 39708 KB Output is correct
46 Correct 0 ms 344 KB Output is correct
47 Correct 0 ms 344 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 41 ms 7064 KB Output is correct
50 Correct 186 ms 30632 KB Output is correct
51 Correct 179 ms 26192 KB Output is correct
52 Correct 291 ms 49564 KB Output is correct
53 Correct 65 ms 16160 KB Output is correct
54 Correct 85 ms 20816 KB Output is correct
55 Correct 156 ms 28244 KB Output is correct
56 Correct 308 ms 51536 KB Output is correct
57 Correct 70 ms 18080 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 1 ms 344 KB Output is correct
60 Correct 4 ms 1116 KB Output is correct
61 Correct 68 ms 18068 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 40 ms 7352 KB Output is correct
66 Correct 61 ms 18192 KB Output is correct
67 Correct 61 ms 18256 KB Output is correct
68 Correct 62 ms 18056 KB Output is correct
69 Correct 70 ms 18312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1376 KB Output is correct
7 Correct 150 ms 26116 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1372 KB Output is correct
13 Correct 156 ms 25996 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 4 ms 860 KB Output is correct
17 Correct 69 ms 16160 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 40 ms 6880 KB Output is correct
21 Correct 163 ms 26196 KB Output is correct
22 Correct 156 ms 26192 KB Output is correct
23 Correct 160 ms 26124 KB Output is correct
24 Correct 156 ms 26084 KB Output is correct
25 Correct 61 ms 16212 KB Output is correct
26 Correct 60 ms 16212 KB Output is correct
27 Correct 161 ms 26104 KB Output is correct
28 Correct 153 ms 26128 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 7 ms 1372 KB Output is correct
37 Correct 155 ms 26076 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 12 ms 3160 KB Output is correct
41 Correct 490 ms 73040 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 6 ms 2036 KB Output is correct
45 Correct 250 ms 39708 KB Output is correct
46 Correct 0 ms 344 KB Output is correct
47 Correct 0 ms 344 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 41 ms 7064 KB Output is correct
50 Correct 186 ms 30632 KB Output is correct
51 Correct 179 ms 26192 KB Output is correct
52 Correct 291 ms 49564 KB Output is correct
53 Correct 65 ms 16160 KB Output is correct
54 Correct 85 ms 20816 KB Output is correct
55 Correct 156 ms 28244 KB Output is correct
56 Correct 308 ms 51536 KB Output is correct
57 Correct 70 ms 18080 KB Output is correct
58 Correct 1 ms 344 KB Output is correct
59 Correct 0 ms 344 KB Output is correct
60 Correct 0 ms 344 KB Output is correct
61 Correct 40 ms 6792 KB Output is correct
62 Correct 164 ms 26152 KB Output is correct
63 Correct 158 ms 26140 KB Output is correct
64 Correct 159 ms 26148 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 39 ms 7252 KB Output is correct
67 Correct 173 ms 30700 KB Output is correct
68 Correct 148 ms 26404 KB Output is correct
69 Correct 293 ms 49476 KB Output is correct
70 Correct 1 ms 344 KB Output is correct
71 Correct 0 ms 344 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 40 ms 6868 KB Output is correct
74 Correct 171 ms 30820 KB Output is correct
75 Correct 169 ms 27888 KB Output is correct
76 Correct 161 ms 27060 KB Output is correct
77 Correct 157 ms 26132 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 1 ms 344 KB Output is correct
80 Correct 4 ms 1116 KB Output is correct
81 Correct 68 ms 18068 KB Output is correct
82 Correct 0 ms 348 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 1 ms 348 KB Output is correct
85 Correct 40 ms 7352 KB Output is correct
86 Correct 61 ms 18192 KB Output is correct
87 Correct 61 ms 18256 KB Output is correct
88 Correct 62 ms 18056 KB Output is correct
89 Correct 70 ms 18312 KB Output is correct
90 Correct 0 ms 348 KB Output is correct
91 Correct 1 ms 348 KB Output is correct
92 Correct 3 ms 940 KB Output is correct
93 Correct 65 ms 18108 KB Output is correct
94 Correct 1 ms 348 KB Output is correct
95 Correct 0 ms 348 KB Output is correct
96 Incorrect 1 ms 500 KB Answer gives possible 1 while actual possible 0
97 Halted 0 ms 0 KB -