Submission #984312

# Submission time Handle Problem Language Result Execution time Memory
984312 2024-05-16T13:07:23 Z CSQ31 Connecting Supertrees (IOI20_supertrees) C++17
56 / 100
169 ms 33924 KB
#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;
#define sz(a) (int)(a.size())
int p[1000][1000],q[1000][1000],ans[1000][1000];
void add(int v,int u){
	ans[v][u] = ans[u][v] = 1;
}
int construct(vector<vector<int>> P) {
	int n = sz(P);
	for (int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			p[i][j] = P[i][j];
			if(p[i][j] == 3)return 0;
		}
	}
	//find all nodes connected to 1
	//then nodes with p(1,v) = 1
	//this has to form a tree
	//repeat forming many trees then link the trees in a cycle
	vector<int>ded(n,0);
	for(int i=0;i<n;i++){
		if(ded[i])continue;
		vector<int>comp;
		vector<bool>incomp(n,0);
		for(int j=0;j<n;j++){
			if(ded[j])continue;
			if(p[i][j]){
				incomp[j] = 1;
				comp.push_back(j);
				ded[j] = 1;
			}
		}
		//for(int x:comp)cout<<x<<" ";
		//cout<<'\n';
		vector<vector<int>>trees;
		while(!comp.empty()){
			int v = comp[0];
			vector<int>tree,tmp;
			for(int u:comp){
				if(p[u][v] == 1)tree.push_back(u);
				else tmp.push_back(u);
			}
			trees.push_back(tree);
			comp = tmp;
		}
		int ss = sz(trees);
		if(ss > 1)add(trees[0][0],trees[ss-1][0]);
		for(int i=0;i<ss;i++){
			if(i+1<sz(trees))add(trees[i][0],trees[i+1][0]);
			for(int j=0;j+1<sz(trees[i]);j++)add(trees[i][j],trees[i][j+1]);
			
			for(int x:trees[i]){
				vector<bool>intree(n,0);
				for(int y:trees[i]){
					q[x][y] = 1;
					intree[y] = 1;
				}
				for(int j=0;j<n;j++){
					if(incomp[j] && !intree[j])q[x][j] = q[j][x] = 2;
				}
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(q[i][j] != p[i][j])return 0;
		}
	}
	vector<vector<int>>fin(n);
	for(int i=0;i<n;i++){
		fin[i].assign(n,0);
		for(int j=0;j<n;j++)fin[i][j] = ans[i][j];
	}
	build(fin);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4600 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 9 ms 11612 KB Output is correct
7 Correct 151 ms 33820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4600 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 9 ms 11612 KB Output is correct
7 Correct 151 ms 33820 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 7 ms 9308 KB Output is correct
13 Correct 144 ms 31704 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 4 ms 11100 KB Output is correct
17 Correct 62 ms 20052 KB Output is correct
18 Correct 1 ms 4852 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 38 ms 16272 KB Output is correct
21 Correct 145 ms 33800 KB Output is correct
22 Correct 160 ms 33872 KB Output is correct
23 Correct 155 ms 33824 KB Output is correct
24 Correct 146 ms 33616 KB Output is correct
25 Correct 60 ms 20004 KB Output is correct
26 Correct 58 ms 19984 KB Output is correct
27 Correct 150 ms 33876 KB Output is correct
28 Correct 161 ms 33732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Incorrect 1 ms 4444 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 42 ms 16468 KB Output is correct
5 Correct 148 ms 33876 KB Output is correct
6 Correct 146 ms 33872 KB Output is correct
7 Correct 151 ms 33876 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 37 ms 16208 KB Output is correct
10 Correct 158 ms 33872 KB Output is correct
11 Correct 145 ms 33896 KB Output is correct
12 Correct 169 ms 33924 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 38 ms 16152 KB Output is correct
17 Correct 145 ms 33824 KB Output is correct
18 Correct 154 ms 33824 KB Output is correct
19 Correct 146 ms 33804 KB Output is correct
20 Correct 144 ms 33620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4600 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 9 ms 11612 KB Output is correct
7 Correct 151 ms 33820 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 7 ms 9308 KB Output is correct
13 Correct 144 ms 31704 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 4 ms 11100 KB Output is correct
17 Correct 62 ms 20052 KB Output is correct
18 Correct 1 ms 4852 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 38 ms 16272 KB Output is correct
21 Correct 145 ms 33800 KB Output is correct
22 Correct 160 ms 33872 KB Output is correct
23 Correct 155 ms 33824 KB Output is correct
24 Correct 146 ms 33616 KB Output is correct
25 Correct 60 ms 20004 KB Output is correct
26 Correct 58 ms 19984 KB Output is correct
27 Correct 150 ms 33876 KB Output is correct
28 Correct 161 ms 33732 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4440 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Incorrect 1 ms 4444 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4600 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 9 ms 11612 KB Output is correct
7 Correct 151 ms 33820 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 7 ms 9308 KB Output is correct
13 Correct 144 ms 31704 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 4 ms 11100 KB Output is correct
17 Correct 62 ms 20052 KB Output is correct
18 Correct 1 ms 4852 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 38 ms 16272 KB Output is correct
21 Correct 145 ms 33800 KB Output is correct
22 Correct 160 ms 33872 KB Output is correct
23 Correct 155 ms 33824 KB Output is correct
24 Correct 146 ms 33616 KB Output is correct
25 Correct 60 ms 20004 KB Output is correct
26 Correct 58 ms 19984 KB Output is correct
27 Correct 150 ms 33876 KB Output is correct
28 Correct 161 ms 33732 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4440 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Incorrect 1 ms 4444 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -