Submission #1078715

# Submission time Handle Problem Language Result Execution time Memory
1078715 2024-08-28T05:00:18 Z Faisal_Saqib Connecting Supertrees (IOI20_supertrees) C++17
21 / 100
942 ms 35904 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
const int N=1e3;
int reach[N][N],tree_case[N][N];
int par[N];
void init(int n)
{
	for(int i=0;i<n;i++)
		par[i]=i;
}
int get(int x)
{
	if(par[x]==x)return x;
	return par[x]=get(par[x]);
}
bool merge(int x,int y)
{
	x=get(x);
	y=get(y);
	if(x==y)return 0;
	par[y]=x;
	return 1;
}
vector<int> ma[N];
int head;
void dfs(int x)
{
	reach[head][x]=1;
	for(auto y:ma[x])
		if(!reach[head][y])
			dfs(y);
}
int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	init(n);
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			tree_case[i][j]=reach[i][j]=0;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			if(p[i][j]==1)
			{
				tree_case[i][j]=tree_case[j][i]=merge(i,j);
				ma[i].push_back(j);
				ma[j].push_back(i);
			}
		}
	}
	vector<vector<int>> answer(n,vector<int>(n,0));
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			answer[i][j]=tree_case[i][j];
			reach[i][j]=0;
		}
		head=i;
		dfs(i);
		for(int j=0;j<n;j++)
		{
			if(reach[i][j]!=p[i][j])
			{
				return 0;
			}
		}
	}
	build(answer);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 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 432 KB Output is correct
6 Correct 13 ms 3092 KB Output is correct
7 Correct 942 ms 35904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 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 432 KB Output is correct
6 Correct 13 ms 3092 KB Output is correct
7 Correct 942 ms 35904 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 360 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 2904 KB Output is correct
13 Correct 121 ms 31868 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 7 ms 2652 KB Output is correct
17 Correct 72 ms 24680 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 32 ms 10328 KB Output is correct
21 Correct 135 ms 32340 KB Output is correct
22 Correct 120 ms 31824 KB Output is correct
23 Correct 326 ms 33876 KB Output is correct
24 Correct 125 ms 31912 KB Output is correct
25 Correct 63 ms 22476 KB Output is correct
26 Correct 60 ms 21912 KB Output is correct
27 Correct 344 ms 34968 KB Output is correct
28 Correct 128 ms 31824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Answer gives possible 0 while actual possible 1
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Answer gives possible 0 while actual possible 1
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 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 432 KB Output is correct
6 Correct 13 ms 3092 KB Output is correct
7 Correct 942 ms 35904 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 360 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 2904 KB Output is correct
13 Correct 121 ms 31868 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 7 ms 2652 KB Output is correct
17 Correct 72 ms 24680 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 32 ms 10328 KB Output is correct
21 Correct 135 ms 32340 KB Output is correct
22 Correct 120 ms 31824 KB Output is correct
23 Correct 326 ms 33876 KB Output is correct
24 Correct 125 ms 31912 KB Output is correct
25 Correct 63 ms 22476 KB Output is correct
26 Correct 60 ms 21912 KB Output is correct
27 Correct 344 ms 34968 KB Output is correct
28 Correct 128 ms 31824 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Incorrect 0 ms 348 KB Answer gives possible 0 while actual possible 1
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 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 432 KB Output is correct
6 Correct 13 ms 3092 KB Output is correct
7 Correct 942 ms 35904 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 360 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 2904 KB Output is correct
13 Correct 121 ms 31868 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 7 ms 2652 KB Output is correct
17 Correct 72 ms 24680 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 32 ms 10328 KB Output is correct
21 Correct 135 ms 32340 KB Output is correct
22 Correct 120 ms 31824 KB Output is correct
23 Correct 326 ms 33876 KB Output is correct
24 Correct 125 ms 31912 KB Output is correct
25 Correct 63 ms 22476 KB Output is correct
26 Correct 60 ms 21912 KB Output is correct
27 Correct 344 ms 34968 KB Output is correct
28 Correct 128 ms 31824 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Incorrect 0 ms 348 KB Answer gives possible 0 while actual possible 1
34 Halted 0 ms 0 KB -