Submission #300279

# Submission time Handle Problem Language Result Execution time Memory
300279 2020-09-17T03:57:46 Z aljasdlas Connecting Supertrees (IOI20_supertrees) C++14
21 / 100
265 ms 30200 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;

bool possible = true;
vector<vector<int>> b;
int n;
bitset<1005> vis;
bitset<1005> isOne;
vector<int> AdjList[1005];

vector<vector<int>> components;
int compNum[1005];
vector<vector<int>> p;

void dfs(int u) {
// << u << " ";
	vis[u] = 1;
	compNum[u] = components.size();
	components.back().push_back(u);
	for(auto &v: AdjList[u])
		if(!vis[v])
			dfs(v);
}


int construct(vector<vector<int>> p_) {
	p = p_;
	n = p.size();
	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++)
			if(p[i][j] != 0)
				AdjList[i].push_back(j);

	for (int i = 0; i < n; i++) {
		vector<int> row;
		row.resize(n);
		b.push_back(row);
	}

	vis.reset();

	for(int i = 0; i < n; i++)
		if(!vis[i]) {
			components.push_back(vector<int>(0));
		// << "Comp " << components.size() << ": ";
			dfs(i);
		// << endl;
		}

	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++)
			if(compNum[i] == compNum[j] && p[i][j] == 0)
				return 0;
			else if(compNum[i] != compNum[j] && p[i][j] > 0)
				return 0;

	for(auto &v: components) {
		isOne.reset();
		if(v.size() == 1)
			continue;
		for(auto &x: v) {
			for(auto &y: v) {
				if(x == y) continue;
				if(p[x][y] == 1)
					isOne[x]=isOne[y]=1;
			}
		}

		for(auto &x: v) {
			for(auto &y: v) {
				if(x == y) continue;
				if(isOne[x]) {
					if(isOne[y]) {
						if(p[x][y] != 1) return 0;
					}
				}
			}
		}

		vector<int> is[3];
		for(auto &x: v)
			if(isOne[x]) is[1].push_back(x);
			else is[2].push_back(x);
		
		
	// << "Is 1: "; for(auto x: is[1]) cerr << x << " "; cerr << endl;
	// << "Is 2: "; for(auto x: is[2]) cerr << x << " "; cerr << endl;

		if(is[2].size() == 1) return 0;
		if(is[2].size() == 0) {
			for(int i = 1; i < is[1].size(); i++) {
				b[is[1][i-1]][is[1][i]] = 1;
				b[is[1][i]][is[1][i-1]] = 1;
			}
		} else if(is[1].size() == 0) {
			for(int i = 1; i < is[2].size(); i++) {
				b[is[2][i-1]][is[2][i]] = 1;
				b[is[2][i]][is[2][i-1]] = 1;
			}
			b[is[2][is[2].size()-1]][is[2][0]] = 1;
			b[is[2][0]][is[2][is[2].size()-1]] = 1;
		} else {
			for(int i = 1; i < is[1].size(); i++) {
				b[is[1][i-1]][is[1][i]] = 1;
				b[is[1][i]][is[1][i-1]] = 1;
			}
			for(int i = 1; i < is[2].size(); i++) {
				b[is[2][i-1]][is[2][i]] = 1;
				b[is[2][i]][is[2][i-1]] = 1;
			}
			b[is[2][0]][is[1][is[1].size()-1]] = 1;
			b[is[1][is[1].size()-1]][is[2][0]] = 1;
			b[is[2][is[2].size()-1]][is[1][is[1].size()-1]] = 1;
			b[is[1][is[1].size()-1]][is[2][is[2].size()-1]] = 1;
		}
	}

	if(!possible)
		return 0;
	
	build(b);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:92:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |    for(int i = 1; i < is[1].size(); i++) {
      |                   ~~^~~~~~~~~~~~~~
supertrees.cpp:97:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |    for(int i = 1; i < is[2].size(); i++) {
      |                   ~~^~~~~~~~~~~~~~
supertrees.cpp:104:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |    for(int i = 1; i < is[1].size(); i++) {
      |                   ~~^~~~~~~~~~~~~~
supertrees.cpp:108:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |    for(int i = 1; i < is[2].size(); i++) {
      |                   ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 1664 KB Output is correct
7 Correct 262 ms 30200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 1664 KB Output is correct
7 Correct 262 ms 30200 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 10 ms 1408 KB Output is correct
13 Correct 247 ms 26104 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 1152 KB Output is correct
17 Correct 122 ms 18680 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 61 ms 6904 KB Output is correct
21 Correct 250 ms 26616 KB Output is correct
22 Correct 248 ms 26104 KB Output is correct
23 Correct 258 ms 28152 KB Output is correct
24 Correct 244 ms 26104 KB Output is correct
25 Correct 108 ms 16632 KB Output is correct
26 Correct 104 ms 16248 KB Output is correct
27 Correct 264 ms 29176 KB Output is correct
28 Correct 244 ms 26104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Incorrect 1 ms 384 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 63 ms 6904 KB Output is correct
5 Correct 248 ms 26616 KB Output is correct
6 Correct 242 ms 26232 KB Output is correct
7 Correct 265 ms 28280 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 64 ms 7032 KB Output is correct
10 Correct 254 ms 26616 KB Output is correct
11 Correct 260 ms 26104 KB Output is correct
12 Correct 259 ms 29176 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Incorrect 28 ms 4352 KB Answer gives possible 0 while actual possible 1
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 1664 KB Output is correct
7 Correct 262 ms 30200 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 10 ms 1408 KB Output is correct
13 Correct 247 ms 26104 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 1152 KB Output is correct
17 Correct 122 ms 18680 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 61 ms 6904 KB Output is correct
21 Correct 250 ms 26616 KB Output is correct
22 Correct 248 ms 26104 KB Output is correct
23 Correct 258 ms 28152 KB Output is correct
24 Correct 244 ms 26104 KB Output is correct
25 Correct 108 ms 16632 KB Output is correct
26 Correct 104 ms 16248 KB Output is correct
27 Correct 264 ms 29176 KB Output is correct
28 Correct 244 ms 26104 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Incorrect 1 ms 384 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 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 11 ms 1664 KB Output is correct
7 Correct 262 ms 30200 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 10 ms 1408 KB Output is correct
13 Correct 247 ms 26104 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 1152 KB Output is correct
17 Correct 122 ms 18680 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 61 ms 6904 KB Output is correct
21 Correct 250 ms 26616 KB Output is correct
22 Correct 248 ms 26104 KB Output is correct
23 Correct 258 ms 28152 KB Output is correct
24 Correct 244 ms 26104 KB Output is correct
25 Correct 108 ms 16632 KB Output is correct
26 Correct 104 ms 16248 KB Output is correct
27 Correct 264 ms 29176 KB Output is correct
28 Correct 244 ms 26104 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Incorrect 1 ms 384 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -