Submission #301669

# Submission time Handle Problem Language Result Execution time Memory
301669 2020-09-18T05:52:11 Z Muhammetali Connecting Supertrees (IOI20_supertrees) C++14
Compilation error
0 ms 0 KB
#include "supertrees.h"
#include <bits/stdc++.h>
#define mp make_pair
#define f first
#define s second
#define sz(x) (int)(x).size()
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
vi get_comp(vector<vi>& adj,vector<bool>& vis,int k)
{
	assert(vis[k]);
	vis[k]=1;
	vi comp(1,k);
	for (int i=0;i<sz(comp);i++)
	{
		assert(vis[comp[i]]);
		for (int j:adj[comp[i]])
		{
			if (!vis[j])
			{
				vis[comp[i]]=1;
				comp.pb(i);
			}
		}
	}
	return comp;
}
int construct(vector<vi> p)
{
	int n=sz(p);
	vector<vi> ans(n,vi(n));
	vector<vi> adjtree(n),adjcycl(n);
	for (int i=0;i<n;i++)
	{
		for (int j=0;j<n;j++)
		{
			if (p[i][j]==3)return 0;
			if (p[i][j]==1)adjtree[i].pb(j);
		}
	}
	vector<vi>trees,roots;
	vector<bool> vis(n);
	for (int i=0;i<n;i++)
	{
		if (!vis[i])
		{
			trees.pb(get_comp(adjtree,vis,i));
			roots.pb(trees.bk.bk);
		}
	}
	for (int i:trees)
	{
		for (int j:sz(trees[i]))
		{
			ans[i][j]=1;
			ans[j][i]=1;
		}
	}
	for (auto i:roots)
	{
		for (auto j:roots)
		{
			if (p[i][j]==2)adjcycl[i].pb(j);
		}
	}
	vis=vector<bool>(n);
	for (int i:roots)
	{
		if (!vis[i])
		{
			vi v=get_comp(adjcycl,vis,i);
			for (int i:v)
			{
				for (int j:v)
				{
					if (p[i][j]!=2 && i!=j)return 0;
				}
			}
			if (sz(v)>=2)return 0;
			for (int i:v)
			{
				for (int j:v)
				{
					ans[i][j]=2;
				}
			}
		}
	}
	for (int i=0;i<n;i++)
	{
		for (int j=0;j<n;j++)
		{
			ans[i][j]|=ans[j][i];
			ans[j][i]|=ans[i][j];
		}
	}
	for (int i=0;i<n;i++)ans[i][i]=0;
	build(ans);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:60:24: error: no matching function for call to 'std::vector<std::vector<int> >::push_back(__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&)'
   60 |    roots.pb(trees.bk.bk);
      |                        ^
In file included from /usr/include/c++/9/vector:67,
                 from supertrees.h:1,
                 from supertrees.cpp:1:
/usr/include/c++/9/bits/stl_vector.h:1184:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >; std::vector<_Tp, _Alloc>::value_type = std::vector<int>]'
 1184 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:1184:35: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} to 'const value_type&' {aka 'const std::vector<int>&'}
 1184 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/9/bits/stl_vector.h:1200:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >; std::vector<_Tp, _Alloc>::value_type = std::vector<int>]'
 1200 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:1200:30: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} to 'std::vector<std::vector<int> >::value_type&&' {aka 'std::vector<int>&&'}
 1200 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
supertrees.cpp:63:13: error: cannot convert 'std::vector<int>' to 'int' in initialization
   63 |  for (int i:trees)
      |             ^~~~~
supertrees.cpp:6:29: error: 'begin' was not declared in this scope; did you mean 'std::begin'?
    6 | #define sz(x) (int)(x).size()
      |                             ^
supertrees.cpp:65:14: note: in expansion of macro 'sz'
   65 |   for (int j:sz(trees[i]))
      |              ^~
In file included from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:95,
                 from supertrees.cpp:2:
/usr/include/c++/9/valarray:1224:5: note: 'std::begin' declared here
 1224 |     begin(const valarray<_Tp>& __va)
      |     ^~~~~
supertrees.cpp:6:29: error: 'end' was not declared in this scope; did you mean 'std::end'?
    6 | #define sz(x) (int)(x).size()
      |                             ^
supertrees.cpp:65:14: note: in expansion of macro 'sz'
   65 |   for (int j:sz(trees[i]))
      |              ^~
In file included from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:95,
                 from supertrees.cpp:2:
/usr/include/c++/9/valarray:1244:5: note: 'std::end' declared here
 1244 |     end(const valarray<_Tp>& __va)
      |     ^~~
supertrees.cpp:75:9: error: no match for 'operator[]' (operand types are 'std::vector<std::vector<int> >' and 'std::vector<int>')
   75 |    if (p[i][j]==2)adjcycl[i].pb(j);
      |         ^
In file included from /usr/include/c++/9/vector:67,
                 from supertrees.h:1,
                 from supertrees.cpp:1:
/usr/include/c++/9/bits/stl_vector.h:1040:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >; std::vector<_Tp, _Alloc>::reference = std::vector<int>&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1040 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:1040:28: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'}
 1040 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
/usr/include/c++/9/bits/stl_vector.h:1058:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) const [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >; std::vector<_Tp, _Alloc>::const_reference = const std::vector<int>&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1058 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:1058:28: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'}
 1058 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
supertrees.cpp:75:26: error: no match for 'operator[]' (operand types are 'std::vector<std::vector<int> >' and 'std::vector<int>')
   75 |    if (p[i][j]==2)adjcycl[i].pb(j);
      |                          ^
In file included from /usr/include/c++/9/vector:67,
                 from supertrees.h:1,
                 from supertrees.cpp:1:
/usr/include/c++/9/bits/stl_vector.h:1040:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >; std::vector<_Tp, _Alloc>::reference = std::vector<int>&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1040 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:1040:28: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'}
 1040 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
/usr/include/c++/9/bits/stl_vector.h:1058:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) const [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >; std::vector<_Tp, _Alloc>::const_reference = const std::vector<int>&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1058 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:1058:28: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'}
 1058 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
supertrees.cpp:79:13: error: cannot convert 'std::vector<int>' to 'int' in initialization
   79 |  for (int i:roots)
      |             ^~~~~