Submission #838605

# Submission time Handle Problem Language Result Execution time Memory
838605 2023-08-27T12:53:10 Z SoulKnight Connecting Supertrees (IOI20_supertrees) C++17
19 / 100
163 ms 24112 KB
#include "supertrees.h"
#include <vector>
#include <iostream>
#include <algorithm>
#include <map>
#include <numeric>
#include <cstring>

using namespace std;

#define ll long long
#define ln '\n'

const int N = 1000 + 5;

int par[N], rk[N];
map<int, vector<int>> mp;
bool ok = true;


int find(int u){return ((u == par[u])? u: par[u]=find(par[u]));}

void add(int u, int v, int c){
	u = find(u);
	v = find(v);

	// if (rk[u] == -1 && rk[v] == -1){
	// 	rk[u] = rk[v] = c;
	// } else if (rk[u] == -1 && rk[v] == c) rk[u] = c;
	// else if (rk[v] == -1 && rk[u] == c) rk[v] = c;
	// else ok = false;

	if (u != v) par[u] = v;
}


int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	std::vector<std::vector<int>> answer;
	for (int i = 0; i < n; i++) {
		std::vector<int> row;
		row.resize(n);
		answer.push_back(row);
	}

	iota(par, par+n, 0);
	memset(rk, -1, sizeof(rk));


	for (int i = 0; i < n; i++){
		for (int j = i+1; j < n; j++){
			if (p[i][j] == 0) continue;
			add(i, j, p[i][j]);
		}
	}

	if (!ok) return 0;
	for (int i = 0; i < n; i++){
		for (int j = i+1; j < n; j++){
			if (p[i][j] == 0 && find(i) == find(j)) return 0;
		}
	}


	for (int i = 0; i < n; i++){
		mp[find(i)].push_back(i);
	}

	for (auto& [p, v]: mp){
		// cout << p << ln;
		// for (auto& x: v) cout << x << " ";
		// cout << ln;
		// if (rk[p] == 1){
		// 	for (auto& u: v){
		// 		if (u != p) answer[u][p] = answer[p][u] = 1;
		// 	}
		// } else {
		// 	if (v.size() < 2) return 0;

		// 	for (int i = 1; i < v.size(); i++){
		// 		answer[v[i]][v[i-1]] = answer[v[i-1]][v[i]] = 1;
		// 	}
		// 	answer[v.back()][v.front()] = answer[v.front()][v.back()] = 1;
		// }
		if (v.size() == 1) continue;
		if (v.size() == 2) return 0;
		for (int i = 1; i < v.size(); i++){
			answer[v[i]][v[i-1]] = answer[v[i-1]][v[i]] = 1;
		}
		answer[v.back()][v.front()] = answer[v.front()][v.back()] = 1;
	}


	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:87:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |   for (int i = 1; i < v.size(); i++){
      |                   ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 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 212 KB Output is correct
2 Incorrect 0 ms 212 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 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 7 ms 1216 KB Output is correct
9 Correct 154 ms 24112 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1180 KB Output is correct
13 Correct 155 ms 23908 KB Output is correct
14 Correct 1 ms 296 KB Output is correct
15 Correct 0 ms 304 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 72 ms 14084 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 44 ms 6316 KB Output is correct
22 Correct 163 ms 23964 KB Output is correct
23 Correct 150 ms 23940 KB Output is correct
24 Correct 163 ms 23980 KB Output is correct
25 Correct 71 ms 14196 KB Output is correct
26 Correct 67 ms 13996 KB Output is correct
27 Correct 150 ms 23972 KB Output is correct
28 Correct 159 ms 23928 KB Output is correct
29 Correct 66 ms 14084 KB Output is correct
# 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 Incorrect 0 ms 212 KB Too many ways to get from 1 to 4, should be 1 found no less than 2
4 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 Answer gives possible 0 while actual possible 1
3 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 Answer gives possible 0 while actual possible 1
3 Halted 0 ms 0 KB -