Submission #733869

# Submission time Handle Problem Language Result Execution time Memory
733869 2023-05-01T11:23:08 Z ismayil Connecting Supertrees (IOI20_supertrees) C++17
19 / 100
200 ms 22056 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e3 + 3;
int par[MAX];
int find(int u){
	if(par[u] < 0) return u;
	return par[u] = find(par[u]);
}
bool unite(int u, int v){
	u = find(u), v = find(v);
	if(u == v) return false;
	if(par[u] > par[v]) swap(u, v);
	par[u] += par[v];
	par[v] = u;
	return true;
}
int construct(vector<vector<int>> p) 
{
	memset(par, -1, sizeof(par));
	int n = p.size();
	vector<vector<int>> answer(n, vector<int>(n, 0));
	int mark[n] = {0};
	for (int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(p[i][j] == 2){
				unite(i, j);
			} 
		}
	}
	for (int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(find(i) == find(j) && p[i][j] == 0) return 0;
		}
	}
	for(int i = 0; i < n; i++){
		if(mark[find(i)]) continue;
		mark[find(i)] = 1;
		vector<int> v;
		for(int j = 0; j < n; j++){
			if(find(i) == find(j)){
				v.push_back(j);
			}
		}
		if(v.size() == 1) continue;
		if(v.size() == 2) return 0;
		for(int j = 0; j < v.size() - 1; j++) answer[v[j]][v[j + 1]] = answer[v[j + 1]][v[j]] = 1;
		answer[v[v.size() - 1]][v[0]] = answer[v[0]][v[v.size() - 1]] = 1;
	}
	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:47:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |   for(int j = 0; j < v.size() - 1; j++) answer[v[j]][v[j + 1]] = answer[v[j + 1]][v[j]] = 1;
      |                  ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Too few ways to get from 0 to 1, should be 1 found 0
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 Too few ways to get from 0 to 1, should be 1 found 0
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 8 ms 1132 KB Output is correct
9 Correct 188 ms 22020 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 8 ms 1196 KB Output is correct
13 Correct 187 ms 22020 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 4 ms 720 KB Output is correct
17 Correct 84 ms 12052 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 47 ms 5708 KB Output is correct
22 Correct 180 ms 21968 KB Output is correct
23 Correct 189 ms 22024 KB Output is correct
24 Correct 188 ms 21964 KB Output is correct
25 Correct 76 ms 12048 KB Output is correct
26 Correct 74 ms 12108 KB Output is correct
27 Correct 187 ms 21948 KB Output is correct
28 Correct 200 ms 22056 KB Output is correct
29 Correct 75 ms 12044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Too few ways to get from 1 to 2, should be 1 found 0
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 Too few ways to get from 0 to 1, should be 1 found 0
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 Too few ways to get from 0 to 1, should be 1 found 0
3 Halted 0 ms 0 KB -