Submission #800687

# Submission time Handle Problem Language Result Execution time Memory
800687 2023-08-01T18:10:05 Z APROHACK Connecting Supertrees (IOI20_supertrees) C++17
56 / 100
166 ms 26032 KB
#include "supertrees.h"
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
using namespace std;
vector<vector<int>>P;
vector<std::vector<int>> answer;
bool vis[1003];
int dsu1[1003];
int n;
const bool debug = false;
void ponerPuente(int a, int b){
	answer[a][b] = 1;
	answer[b][a] = 1;
	if(debug)cout << "puente puesto " << a << " - " << b << endl;
}
int findd(int k){
	if(dsu1[k] == k )return k;
	return dsu1[k] = findd(dsu1[k]);
}
void join1(int a, int b){
	a = findd(a);
	b = findd(b);
	if(a == b)return ;
	dsu1[a] = b;
}


int construct(std::vector<std::vector<int>> p) {
	n = p.size();
	P = p;
	
	memset(vis, false, sizeof vis);
	for(int i = 0 ; i < n ; i ++)dsu1[i] = i;
	vector<int> row;
	for(int j = 0 ;  j < n ; j ++)row.pb(0);
	for (int i = 0; i < n; i++) {
		answer.push_back(row);
	}
	bool isInG[n+1];
	memset(isInG, false, sizeof isInG);
	for(int i = 0 ; i < n ; i ++){
		if(vis[i])continue;
		set<int>grupo1;
		
		
		for(int j = 0 ; j < n ; j ++){
			if(p[i][j] == 1){
				grupo1.insert(j);
				isInG[j] = true;
			}
		}
		vector<int>g;
		for(auto j :grupo1){
			g.pb(j);
		}
		for(auto j : g){
			for(int x = 0 ; x < n ; x ++){
				if(p[j][x] == 1 and !isInG[x])return 0;
				if(p[j][x] == 0 and isInG[x])return 0;
				if(p[j][x] == 2 and isInG[x])return 0; // !!
			}
		}
		for(auto j : g){
			isInG[j] = false;
			vis[j] = true;
		}
		for(int j = 1 ; j < g.size() ; j ++){
			ponerPuente(g[j-1], g[j]);
			join1(g[j-1], g[j]);
		}
	}
	//cout << " uniones con 1 hechas " << endl;
	memset(vis, false, sizeof vis);
	for(int i = 0 ; i < n ; i++){
		if(vis[i])continue;
		vis[i] = true;
		set<int>grupo2;
		for(int j = 0 ; j < n ; j ++){
			if(p[i][j] == 2){
				if(vis[j])return 0;
				grupo2.insert(j);
				isInG[j] = true;
			}
		}
		if(grupo2.size() == 0)continue;
		grupo2.insert(i);
		isInG[i] = true;
		if(grupo2.size() <= 2)return 0;
		vector<int>g;
		if(debug)cout << "Nuevo grupo de 2 desde " << i << endl;
		for(auto j :grupo2){
			g.pb(j);
			if(debug)cout << j << " " ;
		}
		if(debug)cout << endl;
		for(auto j : g){
			if(!isInG[j])continue;
			//cout << "revisando en " << j << endl;
			for(int x = 0 ; x < n ; x ++){
				if(p[j][x] == 1 and isInG[x] and x != j){
					isInG[x] = false;
					grupo2.erase(x);
					if(debug)cout << x << " eliminado " << endl;
				}
				if(p[j][x] == 0 and isInG[x])return 0;
			}
		}
		for(auto j : g)isInG[j] = false;
		g.clear();
		for(auto j :grupo2)g.pb(j);
		if(g.size() <= 2)return 0;
		for(int j = 1 ; j < g.size() ; j ++){
			ponerPuente(g[j-1], g[j]);
		}
		
		ponerPuente(g[0], g.back());
		vector<int>allNodes;
		for(int i = 0 ; i < n ; i ++){
			if(p[g[0]][i] > 0)allNodes.pb(i);
		}
		for(auto j : allNodes)isInG[j] = true;
		
		for(int j = 0 ; i < allNodes.size() ; i ++){
			for(int x = 0 ; x < n ; x ++){
				if(findd(allNodes[j]) == findd(x) and isInG[x])continue;
				if(findd(allNodes[j]) == findd(x))return 0;
				if(isInG[x] and p[allNodes[j]][x] != 2) return 0;
				if(!isInG[x] and p[allNodes[j]][x] != 0)return 0;
			}
		}
		for(auto j : allNodes){
			vis[j] = true;
			isInG[j] = false;
		}
	}
	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:70:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |   for(int j = 1 ; j < g.size() ; j ++){
      |                   ~~^~~~~~~~~~
supertrees.cpp:115:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |   for(int j = 1 ; j < g.size() ; j ++){
      |                   ~~^~~~~~~~~~
supertrees.cpp:126:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  126 |   for(int j = 0 ; i < allNodes.size() ; i ++){
      |                   ~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1308 KB Output is correct
7 Correct 159 ms 25908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1308 KB Output is correct
7 Correct 159 ms 25908 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1364 KB Output is correct
13 Correct 153 ms 25992 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 70 ms 16008 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 38 ms 6668 KB Output is correct
21 Correct 151 ms 26012 KB Output is correct
22 Correct 158 ms 26004 KB Output is correct
23 Correct 156 ms 26004 KB Output is correct
24 Correct 154 ms 25988 KB Output is correct
25 Correct 68 ms 16012 KB Output is correct
26 Correct 68 ms 16004 KB Output is correct
27 Correct 154 ms 26008 KB Output is correct
28 Correct 161 ms 26032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 6 ms 1364 KB Output is correct
9 Correct 155 ms 25988 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1364 KB Output is correct
13 Correct 164 ms 26004 KB Output is correct
14 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 40 ms 6724 KB Output is correct
5 Correct 153 ms 25908 KB Output is correct
6 Correct 152 ms 25932 KB Output is correct
7 Correct 158 ms 25940 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 40 ms 6664 KB Output is correct
10 Correct 154 ms 25984 KB Output is correct
11 Correct 154 ms 25988 KB Output is correct
12 Correct 164 ms 25988 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 39 ms 6672 KB Output is correct
17 Correct 166 ms 25984 KB Output is correct
18 Correct 155 ms 26000 KB Output is correct
19 Correct 154 ms 25988 KB Output is correct
20 Correct 155 ms 25932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1308 KB Output is correct
7 Correct 159 ms 25908 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1364 KB Output is correct
13 Correct 153 ms 25992 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 70 ms 16008 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 38 ms 6668 KB Output is correct
21 Correct 151 ms 26012 KB Output is correct
22 Correct 158 ms 26004 KB Output is correct
23 Correct 156 ms 26004 KB Output is correct
24 Correct 154 ms 25988 KB Output is correct
25 Correct 68 ms 16012 KB Output is correct
26 Correct 68 ms 16004 KB Output is correct
27 Correct 154 ms 26008 KB Output is correct
28 Correct 161 ms 26032 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 6 ms 1364 KB Output is correct
37 Correct 155 ms 25988 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 7 ms 1364 KB Output is correct
41 Correct 164 ms 26004 KB Output is correct
42 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
43 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1308 KB Output is correct
7 Correct 159 ms 25908 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1364 KB Output is correct
13 Correct 153 ms 25992 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 70 ms 16008 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 38 ms 6668 KB Output is correct
21 Correct 151 ms 26012 KB Output is correct
22 Correct 158 ms 26004 KB Output is correct
23 Correct 156 ms 26004 KB Output is correct
24 Correct 154 ms 25988 KB Output is correct
25 Correct 68 ms 16012 KB Output is correct
26 Correct 68 ms 16004 KB Output is correct
27 Correct 154 ms 26008 KB Output is correct
28 Correct 161 ms 26032 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 6 ms 1364 KB Output is correct
37 Correct 155 ms 25988 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 7 ms 1364 KB Output is correct
41 Correct 164 ms 26004 KB Output is correct
42 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
43 Halted 0 ms 0 KB -