Submission #362733

# Submission time Handle Problem Language Result Execution time Memory
362733 2021-02-04T09:26:10 Z abra_stone Connecting Supertrees (IOI20_supertrees) C++14
0 / 100
1 ms 364 KB
#include "supertrees.h"
#include <vector>
#define N 1005
using namespace std;

int n, gc, gr[N], pa[N], a[N][N];
int vc, v[N];
vector<int> rt, ve;
vector<vector<int> > answer;

int uni(int p) {
	if (pa[p] == p) return p;
	else return pa[p] = uni(pa[p]);
}

void make_tree(int p) {
	int i;
	gr[p] = gc;
	for (i = 0; i < n; i++) {
		if (a[p][i] != 1 || gr[i]) continue;
		answer[p][i] = answer[i][p] = 1;
		pa[uni(i)] = uni(p);
		make_tree(i);
	}
}

void make_cy(int p) {
	int i;
	v[p] = vc;
	ve.push_back(p);
	for (i = 0; i < rt.size(); i++) {
		int ne = rt[i];
		if (a[p][ne] != 2 || v[ne]) continue;
		make_cy(ne);
	}
}

int construct(std::vector<std::vector<int> > P) {
	n = P.size();
	int i, j;
	vector<int> t;
	t.clear();
	for (i = 0; i < n; i++) t.push_back(0);
	for (i = 0; i < n; i++) answer.push_back(t);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			a[i][j] = P[i][j];
			if (a[i][j] == 3) return 0;
		}
	}
	for (i = 0; i < n; i++) pa[i] = i;

//	for (i = 0; i < n; i++) {
//		if (!gr[i]) {
//			gc++;
//			rt.push_back(i);
//			make_tree(i);
//		}
//	}
//	for (i = 0; i < n; i++) {
//		for (j = i + 1; j < n; j++) {
//			if (gr[i] == gr[j] && a[i][j] != 1) return 0;
//			if (gr[i] != gr[j] && a[i][j] == 1) return 0;
//		}
//	}

	for (i = 0; i < n; i++) rt.push_back(i);

	for (i = 0; i < rt.size(); i++) {
		if (!v[rt[i]]) {
			vc++;
			ve.clear();
			make_cy(rt[i]);
			for (i = 1; i < ve.size(); i++) {
				int t1 = ve[i - 1], t2 = ve[i];
//				pa[uni(t1)] = uni(t2);
				answer[t1][t2] = answer[t2][t1] = 1;
			}
			if (ve.size() > 1) {
				int t1 = ve[ve.size() - 1], t2 = ve[0];
//				pa[uni(t1)] = uni(t2);
				answer[t1][t2] = answer[t2][t1] = 1;
			}
		}
	}
	for (i = 0; i < n; i++) {
		for (j = i + 1; j < n; j++) {
//			if (uni(i) == uni(j) && a[i][j] == 0) return 0;
//			if (uni(i) != uni(j) && a[i][j] != 0) return 0;
			if (v[i] == v[j] && a[i][j] == 0) return 0;
			if (v[i] != v[j] && a[i][j] != 0) return 0;
		}
	}
	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'void make_cy(int)':
supertrees.cpp:31:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |  for (i = 0; i < rt.size(); i++) {
      |              ~~^~~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:69:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |  for (i = 0; i < rt.size(); i++) {
      |              ~~^~~~~~~~~~~
supertrees.cpp:74:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |    for (i = 1; i < ve.size(); i++) {
      |                ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Answer gives possible 0 while actual possible 1
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Answer gives possible 0 while actual possible 1
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Incorrect 0 ms 364 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Incorrect 0 ms 364 KB Answer gives possible 0 while actual possible 1
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Answer gives possible 0 while actual possible 1
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Answer gives possible 0 while actual possible 1
3 Halted 0 ms 0 KB -