Submission #591567

# Submission time Handle Problem Language Result Execution time Memory
591567 2022-07-07T15:15:41 Z APROHACK Connecting Supertrees (IOI20_supertrees) C++14
56 / 100
215 ms 23116 KB
#include "supertrees.h"
#include <bits/stdc++.h>
#include <vector>
#define ll long long
#define ff first
#define ss second
using namespace std;
 
int construct(vector< vector<int> > p) {
	int n = p.size();
	vector<vector<int> > answer;
	for (int i = 0; i < n; i++) {
		vector<int> row;
		row.resize(n);
		answer.push_back(row);
	}
	ll cuenta = 0, numeroDeLineas = 0, cuenta2 = 0;
	int unos[n], vis[n], LineaALaQuePertenece[n], dos[n];
	memset(vis, 0, sizeof vis);
	for(int i = 0 ; i <n ; i ++){
		cuenta=0, cuenta2=0;
		for(int j = 0 ; j < n ; j++){
			if(i!=j && p[i][j]==1)cuenta++;
			if(i!=j && p[i][j]==2)cuenta2++;
		}
		unos[i]=cuenta, dos[i]=cuenta2;
		
	}
	/// 1. uno los que solo tienen un camino
	vector<int>recorridos;
	recorridos.resize(n);
	int indxRecorrido = 0, indxCiclo=0;
	for(int cur = 0 ; cur < n ; cur++){
		if(vis[cur])continue;
		indxRecorrido = 1;
		indxCiclo=0;
		recorridos[0]=cur, vis[cur]=1;
		
		//cout << " analizando " << cur << " "<<endl;
		for(int j = 0 ; j < n ; j ++){
			if(cur!=j && p[cur][j]==1){
				recorridos[indxRecorrido]=j;
				indxRecorrido++;
				vis[j]=1;
				////cout<<j<<" ";
			}
		}

		// 2. buscar si estan conectados a algun ciclo.
		vector<int>ciclo;
		ciclo.resize(n);
		for(int j = 0 ; j < n ; j ++){
			if(p[cur][j]==2){
				ciclo[indxCiclo]=j;
				indxCiclo++;
			}
		}

		//3. tengo que unir los de recorridos por una linea
		for(int i = 1 ; i < indxRecorrido ; i++){

			//agregar linea
			LineaALaQuePertenece[recorridos[i]]=numeroDeLineas;
			
			recorridos[i-1], recorridos[i];
			answer[recorridos[i-1]][recorridos[i]]=1;
			answer[recorridos[i]][recorridos[i-1]]=1;

			//cout<<recorridos[i-1]<<" "<<recorridos[i]<<endl;

		}

		//verificar que todos tengan union de 1
		for(int i = 0 ; i < indxRecorrido ; i ++){
			int currrecorrido = 0;
			for(int j = 0 ; j < n ; j++){
				if(currrecorrido < indxRecorrido && j==recorridos[currrecorrido]){
					if(p[recorridos[i]][j]!=1)return 0;
					unos[recorridos[i]]--, unos[j]--;
					currrecorrido++;
				}else{
					if(recorridos[i]==j)continue;
					if(p[recorridos[i]][j]==1)return 0;
				}
				
			}
		}

		//cout<<"Uniones de la linea correctos\n";

		//verificar que todos esten unidos al ciclo con 2
		for(int i = 1 ; i < indxRecorrido ; i++){
			int currciclo = 0;
			for(int j = 0 ; j < n ; j++){
				if(currciclo<indxCiclo && j==ciclo[currciclo] ){
					if(p[recorridos[i]][j]!=2)return 0;
					currciclo++;
				}else if(p[recorridos[i]][j]==2)return 0;
			}
		}

		//cout<<"Uniones al ciclo correctos"<<endl;

		//agregarlinea
		LineaALaQuePertenece[cur]=numeroDeLineas;
		numeroDeLineas++;

	}

	//aqui, todas las lineas ya estan unidas, ahora hay que poner el ciclo

	for(int i = 0 ; i < n ; i ++)//cout<<LineaALaQuePertenece[i]<<" ";
	//cout<<endl;
	memset(vis, 0, sizeof vis);
	bool lineaVisitada[n];
	memset(lineaVisitada, false, sizeof lineaVisitada);
	for(int cur = 0 ; cur < n ; cur ++){
		if(dos[cur]<=0 || vis[cur] || lineaVisitada[LineaALaQuePertenece[cur]])continue;
		//cout<<"!"<<cur<<endl;
		lineaVisitada[LineaALaQuePertenece[cur]]=true;
		//set<int>lineasPorUnir;
		vector<int>representante;
		representante.push_back(cur);
		for(int j = 0 ; j < n ; j++){
			if(p[cur][j] == 2){
				vis[j]=true;
				if(!lineaVisitada[LineaALaQuePertenece[j]]){
					lineaVisitada[LineaALaQuePertenece[j]]=true;
					//cout<<"add"<<j<<endl;
					representante.push_back(j);
				}
			}
		}

		//en lineas por unir estan todas las lineas que estan pegadas al ciclo

		////to do: si el tamaño es 2 no se puede
		if(representante.size()==2){
			return 0;
		}
		for(int i = 0 ; i < representante.size() ; i++){
			ll currepresentante = 0;
			for(int j = 0 ; j < representante.size() ; j++){
				if(i==j)continue;
				if(p[representante[i]][representante[j]]!=2)return 0;
			}
		}
		for(int i = 1 ; i < representante.size() ; i++){
			//cout<<representante[i-1]<<" "<<representante[i]<<endl;
			answer[representante[i-1]][representante[i]]=1;
			answer[representante[i]][representante[i-1]]=1;
		}
		answer[representante[representante.size()-1]][representante[0]]=1;
		answer[representante[0]][representante[representante.size()-1]]=1;

		//cout<<representante[0]<< " " << representante[representante.size()-1]<<endl;
	}

	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:141:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  141 |   for(int i = 0 ; i < representante.size() ; i++){
      |                   ~~^~~~~~~~~~~~~~~~~~~~~~
supertrees.cpp:143:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  143 |    for(int j = 0 ; j < representante.size() ; j++){
      |                    ~~^~~~~~~~~~~~~~~~~~~~~~
supertrees.cpp:142:7: warning: unused variable 'currepresentante' [-Wunused-variable]
  142 |    ll currepresentante = 0;
      |       ^~~~~~~~~~~~~~~~
supertrees.cpp:148:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  148 |   for(int i = 1 ; i < representante.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 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 8 ms 1236 KB Output is correct
7 Correct 211 ms 22900 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 8 ms 1236 KB Output is correct
7 Correct 211 ms 22900 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 300 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1208 KB Output is correct
13 Correct 188 ms 22964 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 86 ms 12956 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 304 KB Output is correct
20 Correct 43 ms 6196 KB Output is correct
21 Correct 195 ms 22860 KB Output is correct
22 Correct 174 ms 23008 KB Output is correct
23 Correct 215 ms 23012 KB Output is correct
24 Correct 170 ms 22988 KB Output is correct
25 Correct 77 ms 13084 KB Output is correct
26 Correct 67 ms 12932 KB Output is correct
27 Correct 183 ms 22868 KB Output is correct
28 Correct 183 ms 22948 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 1 ms 212 KB Output is correct
4 Correct 1 ms 340 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 1208 KB Output is correct
9 Correct 179 ms 23116 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 9 ms 1240 KB Output is correct
13 Correct 192 ms 23004 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 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 49 ms 6196 KB Output is correct
5 Correct 199 ms 22928 KB Output is correct
6 Correct 168 ms 22896 KB Output is correct
7 Correct 199 ms 22992 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 49 ms 6220 KB Output is correct
10 Correct 181 ms 22940 KB Output is correct
11 Correct 177 ms 22852 KB Output is correct
12 Correct 183 ms 22984 KB Output is correct
13 Correct 1 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 43 ms 6188 KB Output is correct
17 Correct 199 ms 22912 KB Output is correct
18 Correct 183 ms 23012 KB Output is correct
19 Correct 181 ms 22920 KB Output is correct
20 Correct 179 ms 22972 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 8 ms 1236 KB Output is correct
7 Correct 211 ms 22900 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 300 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1208 KB Output is correct
13 Correct 188 ms 22964 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 86 ms 12956 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 304 KB Output is correct
20 Correct 43 ms 6196 KB Output is correct
21 Correct 195 ms 22860 KB Output is correct
22 Correct 174 ms 23008 KB Output is correct
23 Correct 215 ms 23012 KB Output is correct
24 Correct 170 ms 22988 KB Output is correct
25 Correct 77 ms 13084 KB Output is correct
26 Correct 67 ms 12932 KB Output is correct
27 Correct 183 ms 22868 KB Output is correct
28 Correct 183 ms 22948 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 304 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 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 1208 KB Output is correct
37 Correct 179 ms 23116 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 9 ms 1240 KB Output is correct
41 Correct 192 ms 23004 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 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 8 ms 1236 KB Output is correct
7 Correct 211 ms 22900 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 300 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1208 KB Output is correct
13 Correct 188 ms 22964 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 86 ms 12956 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 304 KB Output is correct
20 Correct 43 ms 6196 KB Output is correct
21 Correct 195 ms 22860 KB Output is correct
22 Correct 174 ms 23008 KB Output is correct
23 Correct 215 ms 23012 KB Output is correct
24 Correct 170 ms 22988 KB Output is correct
25 Correct 77 ms 13084 KB Output is correct
26 Correct 67 ms 12932 KB Output is correct
27 Correct 183 ms 22868 KB Output is correct
28 Correct 183 ms 22948 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 304 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 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 1208 KB Output is correct
37 Correct 179 ms 23116 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 9 ms 1240 KB Output is correct
41 Correct 192 ms 23004 KB Output is correct
42 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
43 Halted 0 ms 0 KB -