Submission #800686

# Submission time Handle Problem Language Result Execution time Memory
800686 2023-08-01T18:09:46 Z APROHACK Connecting Supertrees (IOI20_supertrees) C++17
0 / 100
1 ms 212 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 = true;
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 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB secret mismatch
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB secret mismatch
3 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 0 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB secret mismatch
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB secret mismatch
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB secret mismatch
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB secret mismatch
3 Halted 0 ms 0 KB -