Submission #800675

# Submission time Handle Problem Language Result Execution time Memory
800675 2023-08-01T17:53:15 Z APROHACK Connecting Supertrees (IOI20_supertrees) C++17
56 / 100
179 ms 28032 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){
				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:114:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  114 |   for(int j = 1 ; j < g.size() ; j ++){
      |                   ~~^~~~~~~~~~
supertrees.cpp:125:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  125 |   for(int j = 0 ; i < allNodes.size() ; i ++){
      |                   ~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1364 KB Output is correct
7 Correct 155 ms 26316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1364 KB Output is correct
7 Correct 155 ms 26316 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 7 ms 1364 KB Output is correct
13 Correct 155 ms 26416 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 5 ms 980 KB Output is correct
17 Correct 72 ms 17012 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 304 KB Output is correct
20 Correct 40 ms 7116 KB Output is correct
21 Correct 179 ms 26356 KB Output is correct
22 Correct 157 ms 26316 KB Output is correct
23 Correct 158 ms 26348 KB Output is correct
24 Correct 156 ms 26372 KB Output is correct
25 Correct 70 ms 16972 KB Output is correct
26 Correct 69 ms 16920 KB Output is correct
27 Correct 163 ms 26308 KB Output is correct
28 Correct 154 ms 26300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 7 ms 1364 KB Output is correct
9 Correct 159 ms 26464 KB Output is correct
10 Correct 1 ms 288 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 8 ms 1340 KB Output is correct
13 Correct 167 ms 26472 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 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 49 ms 7084 KB Output is correct
5 Correct 155 ms 26484 KB Output is correct
6 Correct 155 ms 26512 KB Output is correct
7 Correct 165 ms 26464 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 39 ms 7188 KB Output is correct
10 Correct 159 ms 26500 KB Output is correct
11 Correct 179 ms 26440 KB Output is correct
12 Correct 166 ms 26440 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 0 ms 304 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 43 ms 7156 KB Output is correct
17 Correct 157 ms 27892 KB Output is correct
18 Correct 159 ms 27980 KB Output is correct
19 Correct 161 ms 27892 KB Output is correct
20 Correct 156 ms 28032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1364 KB Output is correct
7 Correct 155 ms 26316 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 7 ms 1364 KB Output is correct
13 Correct 155 ms 26416 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 5 ms 980 KB Output is correct
17 Correct 72 ms 17012 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 304 KB Output is correct
20 Correct 40 ms 7116 KB Output is correct
21 Correct 179 ms 26356 KB Output is correct
22 Correct 157 ms 26316 KB Output is correct
23 Correct 158 ms 26348 KB Output is correct
24 Correct 156 ms 26372 KB Output is correct
25 Correct 70 ms 16972 KB Output is correct
26 Correct 69 ms 16920 KB Output is correct
27 Correct 163 ms 26308 KB Output is correct
28 Correct 154 ms 26300 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 300 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 7 ms 1364 KB Output is correct
37 Correct 159 ms 26464 KB Output is correct
38 Correct 1 ms 288 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 8 ms 1340 KB Output is correct
41 Correct 167 ms 26472 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 1 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1364 KB Output is correct
7 Correct 155 ms 26316 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 7 ms 1364 KB Output is correct
13 Correct 155 ms 26416 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 5 ms 980 KB Output is correct
17 Correct 72 ms 17012 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 304 KB Output is correct
20 Correct 40 ms 7116 KB Output is correct
21 Correct 179 ms 26356 KB Output is correct
22 Correct 157 ms 26316 KB Output is correct
23 Correct 158 ms 26348 KB Output is correct
24 Correct 156 ms 26372 KB Output is correct
25 Correct 70 ms 16972 KB Output is correct
26 Correct 69 ms 16920 KB Output is correct
27 Correct 163 ms 26308 KB Output is correct
28 Correct 154 ms 26300 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 300 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 7 ms 1364 KB Output is correct
37 Correct 159 ms 26464 KB Output is correct
38 Correct 1 ms 288 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 8 ms 1340 KB Output is correct
41 Correct 167 ms 26472 KB Output is correct
42 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
43 Halted 0 ms 0 KB -