Submission #823000

# Submission time Handle Problem Language Result Execution time Memory
823000 2023-08-12T06:52:45 Z fatemetmhr Connecting Supertrees (IOI20_supertrees) C++17
56 / 100
182 ms 26040 KB
// :)

#include "supertrees.h"
#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define fi     first
#define se     second
#define mp     make_pair
#define pb     push_back

typedef long long ll;


const int maxn5 = 1e3 + 10;

vector<vector<int>> ret;
vector <int> tp, av, ver;
bool mark[maxn5], mark2[maxn5];
int n, a[maxn5][maxn5];

void dfs0(int v){
	mark[v] = true;
	ver.pb(v);
	for(int i = 0; i < n; i++) if(a[v][i] > 0 && !mark[i])
		dfs0(i);
}

void dfs1(int v){
	mark2[v] = true;
	av.pb(v);
	for(int i = 0; i < n; i++) if(a[v][i] == 1 && !mark2[i]){
		ret[v][i] = ret[i][v] = 1;
		dfs1(i);
	}
}

int construct(std::vector<std::vector<int>> p) {
	n = p.size();
	for (int i = 0; i < n; i++){
		vector<int> row;
		row.resize(n);
		fill(all(row), 0);
		ret.push_back(row);
		for(int j = 0; j < n; j++)
			a[i][j] = p[i][j];
	}
	for(int i = 0; i < n; i++) if(!mark[i]){
		ver.clear();
		tp.clear();
		dfs0(i);
		for(int j = 0; j < ver.size(); j++) for(int k = 0; k < ver.size(); k++)
			if(a[ver[j]][ver[k]] == 0)
				return 0;
		for(auto u : ver) if(!mark2[u]){
			av.clear();
			dfs1(u);
			for(int i = 0; i < av.size(); i++) for(int j = 0; j < av.size(); j++)
				if(a[av[i]][av[j]] != 1)
					return 0;
			tp.pb(u);
		}
		for(int i = 1; i < int(tp.size()); i++)
			ret[tp[i]][tp[i - 1]] = ret[tp[i - 1]][tp[i]] = 1;
		if(tp.size() > 1)
			ret[tp.back()][tp[0]] = ret[tp[0]][tp.back()] = 1;
	}
	build(ret);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:54:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |   for(int j = 0; j < ver.size(); j++) for(int k = 0; k < ver.size(); k++)
      |                  ~~^~~~~~~~~~~~
supertrees.cpp:54:56: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |   for(int j = 0; j < ver.size(); j++) for(int k = 0; k < ver.size(); k++)
      |                                                      ~~^~~~~~~~~~~~
supertrees.cpp:60:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |    for(int i = 0; i < av.size(); i++) for(int j = 0; j < av.size(); j++)
      |                   ~~^~~~~~~~~~~
supertrees.cpp:60:56: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |    for(int i = 0; i < av.size(); i++) for(int j = 0; j < av.size(); j++)
      |                                                      ~~^~~~~~~~~~~
# 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 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 7 ms 1968 KB Output is correct
7 Correct 158 ms 26008 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 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 7 ms 1968 KB Output is correct
7 Correct 158 ms 26008 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 7 ms 1876 KB Output is correct
13 Correct 157 ms 25932 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 3 ms 1492 KB Output is correct
17 Correct 81 ms 16144 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 40 ms 7668 KB Output is correct
21 Correct 182 ms 26008 KB Output is correct
22 Correct 161 ms 26040 KB Output is correct
23 Correct 163 ms 26008 KB Output is correct
24 Correct 159 ms 25992 KB Output is correct
25 Correct 70 ms 16024 KB Output is correct
26 Correct 65 ms 16008 KB Output is correct
27 Correct 173 ms 25932 KB Output is correct
28 Correct 163 ms 26008 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 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 40 ms 7664 KB Output is correct
5 Correct 161 ms 25948 KB Output is correct
6 Correct 163 ms 25992 KB Output is correct
7 Correct 163 ms 26004 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 40 ms 7688 KB Output is correct
10 Correct 160 ms 25944 KB Output is correct
11 Correct 161 ms 25996 KB Output is correct
12 Correct 172 ms 25972 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 40 ms 7688 KB Output is correct
17 Correct 163 ms 26020 KB Output is correct
18 Correct 165 ms 26000 KB Output is correct
19 Correct 179 ms 25992 KB Output is correct
20 Correct 165 ms 25932 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 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 7 ms 1968 KB Output is correct
7 Correct 158 ms 26008 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 7 ms 1876 KB Output is correct
13 Correct 157 ms 25932 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 3 ms 1492 KB Output is correct
17 Correct 81 ms 16144 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 40 ms 7668 KB Output is correct
21 Correct 182 ms 26008 KB Output is correct
22 Correct 161 ms 26040 KB Output is correct
23 Correct 163 ms 26008 KB Output is correct
24 Correct 159 ms 25992 KB Output is correct
25 Correct 70 ms 16024 KB Output is correct
26 Correct 65 ms 16008 KB Output is correct
27 Correct 173 ms 25932 KB Output is correct
28 Correct 163 ms 26008 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 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 7 ms 1968 KB Output is correct
7 Correct 158 ms 26008 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 7 ms 1876 KB Output is correct
13 Correct 157 ms 25932 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 3 ms 1492 KB Output is correct
17 Correct 81 ms 16144 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 40 ms 7668 KB Output is correct
21 Correct 182 ms 26008 KB Output is correct
22 Correct 161 ms 26040 KB Output is correct
23 Correct 163 ms 26008 KB Output is correct
24 Correct 159 ms 25992 KB Output is correct
25 Correct 70 ms 16024 KB Output is correct
26 Correct 65 ms 16008 KB Output is correct
27 Correct 173 ms 25932 KB Output is correct
28 Correct 163 ms 26008 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 -