Submission #1050064

# Submission time Handle Problem Language Result Execution time Memory
1050064 2024-08-09T07:09:23 Z noyancanturk Connecting Supertrees (IOI20_supertrees) C++17
46 / 100
106 ms 26348 KB
#include "supertrees.h"

#include<bits/stdc++.h>
using namespace std;

const int lim=2000;

#define pb push_back

int n;
bool used[lim];
vector<vector<int>>comps,need,ans;

bool buildcomp(vector<int>&v){
	vector<int>loop;
	vector<vector<int>>chains;
	for(int node:v){
		if(!used[node]){
			used[node]=1;
			chains.pb({});
			for(int i=0;i<n;i++){
				if(need[node][i]==1){
					chains.back().pb(i);
					used[i]=1;
				}
			}
		}
	}
	//verify chains
	for(auto&u:chains){
		for(int i=0;i<u.size();i++){
			for(int j=0;j<u.size();j++){
				if(need[u[i]][u[j]]==2)return 0;
			}
		}
	}
	//verify all
	if(chains.size()==1){
		for(int i=0;i+1<chains[0].size();i++){
			ans[chains[0][i]][chains[0][i+1]]=ans[chains[0][i+1]][chains[0][i]]=1;
		}
		return 1;
	}
	if(chains.size()==2){
		return 0;
	}
	for(int i=0;i<chains.size();i++){
		auto&u=chains[i];
		for(int j=0;j+1<u.size();j++){
			ans[u[j]][u[j+1]]=ans[u[j+1]][u[j]]=1;
		}
		if(i)ans[u[0]][chains[i-1][0]]=ans[chains[i-1][0]][u[0]]=1;
		else ans[u[0]][chains.back()[0]]=ans[chains.back()[0]][u[0]]=1;
	}
	return 1;
}

int construct(std::vector<std::vector<int>> p) {
	need=p;
	n = p.size();
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(p[i][j]==3)return 0;
		}
		if(!used[i]){
			used[i]=1;
			comps.pb({});
			for(int j=0;j<n;j++){
				if(p[i][j]){
					comps.back().pb(j);
					used[j]=1;
				}
			}
		}
		ans.pb(vector<int>(n,0));
	}
	memset(used,0,n);
	for(int i=0;i<comps.size();i++){
		if(!buildcomp(comps[i])){
			return 0;
		}
	}
	build(ans);
	return 1;
}
/*
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);
	}
	build(answer);
	return 1;
}
*/

Compilation message

supertrees.cpp: In function 'bool buildcomp(std::vector<int>&)':
supertrees.cpp:31:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |   for(int i=0;i<u.size();i++){
      |               ~^~~~~~~~~
supertrees.cpp:32:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |    for(int j=0;j<u.size();j++){
      |                ~^~~~~~~~~
supertrees.cpp:39:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |   for(int i=0;i+1<chains[0].size();i++){
      |               ~~~^~~~~~~~~~~~~~~~~
supertrees.cpp:47:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |  for(int i=0;i<chains.size();i++){
      |              ~^~~~~~~~~~~~~~
supertrees.cpp:49:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |   for(int j=0;j+1<u.size();j++){
      |               ~~~^~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:78:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |  for(int i=0;i<comps.size();i++){
      |              ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 4 ms 1372 KB Output is correct
7 Correct 92 ms 26348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 4 ms 1372 KB Output is correct
7 Correct 92 ms 26348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 4 ms 1372 KB Output is correct
13 Correct 104 ms 26120 KB Output is correct
14 Incorrect 0 ms 344 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 4 ms 1372 KB Output is correct
9 Correct 106 ms 26140 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 4 ms 1372 KB Output is correct
13 Correct 92 ms 25956 KB Output is correct
14 Incorrect 1 ms 348 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 24 ms 6716 KB Output is correct
5 Correct 94 ms 25944 KB Output is correct
6 Correct 93 ms 25940 KB Output is correct
7 Correct 99 ms 26080 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 35 ms 6828 KB Output is correct
10 Correct 97 ms 25940 KB Output is correct
11 Correct 92 ms 25936 KB Output is correct
12 Correct 106 ms 25940 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 24 ms 6904 KB Output is correct
17 Correct 94 ms 26144 KB Output is correct
18 Correct 98 ms 25940 KB Output is correct
19 Correct 97 ms 25940 KB Output is correct
20 Correct 96 ms 26192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 4 ms 1372 KB Output is correct
7 Correct 92 ms 26348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 4 ms 1372 KB Output is correct
13 Correct 104 ms 26120 KB Output is correct
14 Incorrect 0 ms 344 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 4 ms 1372 KB Output is correct
7 Correct 92 ms 26348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 4 ms 1372 KB Output is correct
13 Correct 104 ms 26120 KB Output is correct
14 Incorrect 0 ms 344 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -