Submission #733977

# Submission time Handle Problem Language Result Execution time Memory
733977 2023-05-01T12:43:53 Z ismayil Connecting Supertrees (IOI20_supertrees) C++17
56 / 100
233 ms 24004 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e3 + 3;

struct DSU{
	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;
	}
	DSU(){
		memset(par, -1, sizeof(par));
	}
};
int construct(vector<vector<int>> p) 
{
	for(auto i : p) for(auto j : i) if(j == 3) return 0;
	DSU dsu1, dsu2;
	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] == 0 && dsu1.find(i) == dsu1.find(j)) return 0;
			if(p[i][j] != 1) continue;
			if(dsu1.unite(i, j)){
				answer[i][j] = answer[j][i] = 1;
			}
		}
	}
	for (int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(p[dsu1.find(i)][dsu1.find(j)] == 2){
				dsu2.unite(dsu1.find(i), dsu1.find(j));
			} 
		}
	}
	for (int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(dsu2.find(dsu1.find(i)) == dsu2.find(dsu1.find(j)) && p[dsu1.find(i)][dsu1.find(j)] == 0) return 0;
		}
	}
	vector<int> comp[n];
	for(int i = 0; i < n; i++){
		if(mark[dsu1.find(i)]) continue;
		mark[dsu1.find(i)] = 1;
		comp[dsu2.find(dsu1.find(i))].push_back(dsu1.find(i));
	}
	for(auto &v : comp){
		if(v.size() <= 2) continue;
		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:60:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |   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 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 8 ms 1108 KB Output is correct
7 Correct 203 ms 22020 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 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 1108 KB Output is correct
7 Correct 203 ms 22020 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 10 ms 1108 KB Output is correct
13 Correct 176 ms 22024 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 792 KB Output is correct
17 Correct 82 ms 13184 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 48 ms 6220 KB Output is correct
21 Correct 194 ms 23880 KB Output is correct
22 Correct 183 ms 23856 KB Output is correct
23 Correct 208 ms 23792 KB Output is correct
24 Correct 179 ms 23844 KB Output is correct
25 Correct 79 ms 13216 KB Output is correct
26 Correct 77 ms 13276 KB Output is correct
27 Correct 201 ms 23892 KB Output is correct
28 Correct 183 ms 24004 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 Incorrect 0 ms 212 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 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 48 ms 5704 KB Output is correct
5 Correct 197 ms 22092 KB Output is correct
6 Correct 179 ms 22028 KB Output is correct
7 Correct 233 ms 22052 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 48 ms 5708 KB Output is correct
10 Correct 191 ms 22148 KB Output is correct
11 Correct 179 ms 22020 KB Output is correct
12 Correct 210 ms 22088 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 49 ms 5756 KB Output is correct
17 Correct 183 ms 22056 KB Output is correct
18 Correct 202 ms 22028 KB Output is correct
19 Correct 192 ms 22092 KB Output is correct
20 Correct 180 ms 22196 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 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 1108 KB Output is correct
7 Correct 203 ms 22020 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 10 ms 1108 KB Output is correct
13 Correct 176 ms 22024 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 792 KB Output is correct
17 Correct 82 ms 13184 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 48 ms 6220 KB Output is correct
21 Correct 194 ms 23880 KB Output is correct
22 Correct 183 ms 23856 KB Output is correct
23 Correct 208 ms 23792 KB Output is correct
24 Correct 179 ms 23844 KB Output is correct
25 Correct 79 ms 13216 KB Output is correct
26 Correct 77 ms 13276 KB Output is correct
27 Correct 201 ms 23892 KB Output is correct
28 Correct 183 ms 24004 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
33 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 8 ms 1108 KB Output is correct
7 Correct 203 ms 22020 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 10 ms 1108 KB Output is correct
13 Correct 176 ms 22024 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 792 KB Output is correct
17 Correct 82 ms 13184 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 48 ms 6220 KB Output is correct
21 Correct 194 ms 23880 KB Output is correct
22 Correct 183 ms 23856 KB Output is correct
23 Correct 208 ms 23792 KB Output is correct
24 Correct 179 ms 23844 KB Output is correct
25 Correct 79 ms 13216 KB Output is correct
26 Correct 77 ms 13276 KB Output is correct
27 Correct 201 ms 23892 KB Output is correct
28 Correct 183 ms 24004 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -