Submission #838647

# Submission time Handle Problem Language Result Execution time Memory
838647 2023-08-27T14:05:31 Z SoulKnight Connecting Supertrees (IOI20_supertrees) C++17
19 / 100
174 ms 22096 KB
#include "supertrees.h"
#include <vector>
#include <iostream>
#include <numeric>
#include <cstring>

using namespace std;

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

const int N = 1000 + 5;

int par[N], who[N];
vector<int> com[N];


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



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(who, -1, sizeof(who));

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

	// 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++){
		com[find(i)].push_back(i);
	}


	for (int i = 0; i < n; i++){
		if (com[i].size() <= 1) continue;

		vector<int> cycle;

		for (auto& v: com[i]){
			for (auto& j: com[i]){
				if (v == j) continue;
				if (p[v][j] == 2) continue;
				if (p[j][v] == 0) return 0;
				if (who[j] != who[v]) return 0;


				if (who[j] == -1) who[j] = v;
				answer[j][v] = answer[v][j] = 1;
			}
			if (who[v] == -1) {who[v] = v; cycle.push_back(v);}
		}

		if (cycle.size() <= 2) return 0;

		for (int i = 1; i < cycle.size(); i++){
			answer[cycle[i-1]][cycle[i]] = answer[cycle[i]][cycle[i-1]] = 1;
		}
		answer[cycle.front()][cycle.back()] = answer[cycle.back()][cycle.front()] = 1;
	}


	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:73:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |   for (int i = 1; i < cycle.size(); i++){
      |                   ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 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 1 ms 212 KB Output is correct
2 Incorrect 1 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 332 KB Output is correct
2 Correct 1 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 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 7 ms 1108 KB Output is correct
9 Correct 162 ms 22056 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 164 ms 22012 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 69 ms 12064 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 45 ms 5756 KB Output is correct
22 Correct 159 ms 21992 KB Output is correct
23 Correct 160 ms 21976 KB Output is correct
24 Correct 170 ms 22052 KB Output is correct
25 Correct 63 ms 12080 KB Output is correct
26 Correct 67 ms 12068 KB Output is correct
27 Correct 166 ms 22096 KB Output is correct
28 Correct 174 ms 21988 KB Output is correct
29 Correct 64 ms 12188 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 Incorrect 0 ms 212 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 212 KB Output is correct
2 Incorrect 1 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 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Answer gives possible 0 while actual possible 1
3 Halted 0 ms 0 KB -