Submission #952770

# Submission time Handle Problem Language Result Execution time Memory
952770 2024-03-24T18:51:58 Z emad234 Connecting Supertrees (IOI20_supertrees) C++17
21 / 100
176 ms 32000 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>> v, ty;
	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[i][j] != -1 && p[i][j] != ty[i][j])
					return 0;
				if (p[i][j] == 2)
					v[find(i)].push_back(find(j));
				ty[i][j] = p[i][j];
			}
		}
	}
	vector<bool> vis(n);
	for (int i = 0; i < n; i++)
	{
		int prv = -1;
		if (vis[i])
			continue;
		;
		if (v[i].size() == 1)
			return 0;
		v[i].push_back(i);
		for (auto x : v[i])
		{
			vis[x] = 1;
			if (prv != -1)
			{
				b[x][prv] = 1;
				b[prv][x] = 1;
			}
			prv = x;
		}
		if (v[i].size() >= 2)
		{
			b[v[i][0]][v[i][v[i].size() - 1]] = 1;
			b[v[i][v[i].size() - 1]][v[i][0]] = 1;
		}
	}
	build(b);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 440 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 7 ms 1368 KB Output is correct
7 Correct 165 ms 27988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 440 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 7 ms 1368 KB Output is correct
7 Correct 165 ms 27988 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 448 KB Output is correct
12 Correct 7 ms 1372 KB Output is correct
13 Correct 161 ms 28156 KB Output is correct
14 Correct 1 ms 504 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 4 ms 976 KB Output is correct
17 Correct 82 ms 18068 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 40 ms 7232 KB Output is correct
21 Correct 168 ms 28240 KB Output is correct
22 Correct 160 ms 28356 KB Output is correct
23 Correct 172 ms 28340 KB Output is correct
24 Correct 170 ms 28044 KB Output is correct
25 Correct 71 ms 18056 KB Output is correct
26 Correct 68 ms 18196 KB Output is correct
27 Correct 169 ms 27988 KB Output is correct
28 Correct 159 ms 28040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 448 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 7 ms 1372 KB Output is correct
9 Correct 162 ms 28036 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 1624 KB Output is correct
13 Correct 176 ms 32000 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Incorrect 1 ms 348 KB Answer gives possible 1 while actual possible 0
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 444 KB Output is correct
4 Correct 40 ms 7260 KB Output is correct
5 Correct 166 ms 28308 KB Output is correct
6 Correct 160 ms 27988 KB Output is correct
7 Correct 170 ms 27956 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 40 ms 7252 KB Output is correct
10 Correct 161 ms 28604 KB Output is correct
11 Correct 159 ms 27948 KB Output is correct
12 Correct 169 ms 31136 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Incorrect 41 ms 7248 KB b[23][23] is not 0
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 440 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 7 ms 1368 KB Output is correct
7 Correct 165 ms 27988 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 448 KB Output is correct
12 Correct 7 ms 1372 KB Output is correct
13 Correct 161 ms 28156 KB Output is correct
14 Correct 1 ms 504 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 4 ms 976 KB Output is correct
17 Correct 82 ms 18068 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 40 ms 7232 KB Output is correct
21 Correct 168 ms 28240 KB Output is correct
22 Correct 160 ms 28356 KB Output is correct
23 Correct 172 ms 28340 KB Output is correct
24 Correct 170 ms 28044 KB Output is correct
25 Correct 71 ms 18056 KB Output is correct
26 Correct 68 ms 18196 KB Output is correct
27 Correct 169 ms 27988 KB Output is correct
28 Correct 159 ms 28040 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 448 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 7 ms 1372 KB Output is correct
37 Correct 162 ms 28036 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 7 ms 1624 KB Output is correct
41 Correct 176 ms 32000 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Incorrect 1 ms 348 KB Answer gives possible 1 while actual possible 0
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 440 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 7 ms 1368 KB Output is correct
7 Correct 165 ms 27988 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 448 KB Output is correct
12 Correct 7 ms 1372 KB Output is correct
13 Correct 161 ms 28156 KB Output is correct
14 Correct 1 ms 504 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 4 ms 976 KB Output is correct
17 Correct 82 ms 18068 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 40 ms 7232 KB Output is correct
21 Correct 168 ms 28240 KB Output is correct
22 Correct 160 ms 28356 KB Output is correct
23 Correct 172 ms 28340 KB Output is correct
24 Correct 170 ms 28044 KB Output is correct
25 Correct 71 ms 18056 KB Output is correct
26 Correct 68 ms 18196 KB Output is correct
27 Correct 169 ms 27988 KB Output is correct
28 Correct 159 ms 28040 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 448 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 7 ms 1372 KB Output is correct
37 Correct 162 ms 28036 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 7 ms 1624 KB Output is correct
41 Correct 176 ms 32000 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Incorrect 1 ms 348 KB Answer gives possible 1 while actual possible 0
44 Halted 0 ms 0 KB -