Submission #1113488

# Submission time Handle Problem Language Result Execution time Memory
1113488 2024-11-16T16:27:27 Z Nonoze Make them Meet (EGOI24_makethemmeet) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define cmin(a, b) a=min(a, b)
#define cmax(a, b) a=max(a, b)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define int long long

void solve();

signed main() {
	ios::sync_with_stdio(0); cin.tie(0);
	solve();
	return 0;
}

vector<vector<int>> vec;


void print() {
	cout << sz(vec) << endl;
	for (auto &a: vec) {
		for (auto &u: a) cout << u << ' ';
		cout << endl;
	}
	cout << endl;
}

void add(vector<int> &a) { vec.pb(a); }

int n, m;
vector<int> a, cnt;
vector<vector<int>> adj;
vector<bool> visited, visited2, ok, tovisit;

bool dfs(int x) {
	bool flag=0;
	if (ok[x]) flag=1;
	visited2[x]=1;
	for (auto u: adj[x]) if (!visited[u] && !visited2[u]) {
		flag|=dfs(u);
	}
	return tovisit[x]=flag;
}

void dfs2(int x) {
	visited[x]=1;
	cnt[x]++;
	for (auto u: adj[x]) if (!visited[u]) {
		visited2.assign(n, 0);
		tovisit.assign(n, 0);
		dfs(u);
		if (tovisit[u]) dfs2(u);
	}
}


void execute(int x) {
	visited[x]=1;
	for (auto u: adj[x]) if (!visited[u]) {
		visited2.assign(n, 0);
		tovisit.assign(n, 0);
		dfs(u);
		if (tovisit[u]) {
			auto temp=a; temp[x]=0, temp[u]=0;
			add(temp);
			execute(u);
			add(temp);
		}
	}
}

void solve() {
	cin >> n >> m; a.clear(), a.resize(n, 0); iota(all(a), 1);
	adj.clear(), adj.resize(n), ok.clear(), ok.resize(n, 1);
	vector<set<int>> adjbase(n);
	for (int i=0; i<m; i++) {
		int u, v; cin >> u >> v;
		adj[u].pb(v), adj[v].pb(u);
		adjbase[u].insert(v), adjbase[v].insert(u);
	}
	for (int i=0; i<n-1; i++) {
		int best=-1;
		cnt.clear(), cnt.resize(n);
		for (int j=0; j<n; j++) {
			visited.assign(n);
			dfs2(j);
		}
		for (int j=0; j<n; j++) if (ok[j] && (best==-1 || cnt[j]<cnt[best])) best=j;
		visited.assign(n, 0);
		execute(best);
		ok[best]=0;
		for (auto u: adjbase[best]) {
			adjbase[u].erase(best);
		}
		adjbase[best].clear();
	}
	print();
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:93:20: error: no matching function for call to 'std::vector<bool>::assign(long long int&)'
   93 |    visited.assign(n);
      |                    ^
In file included from /usr/include/c++/10/vector:68,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from Main.cpp:1:
/usr/include/c++/10/bits/stl_bvector.h:808:7: note: candidate: 'void std::vector<bool, _Alloc>::assign(std::vector<bool, _Alloc>::size_type, const bool&) [with _Alloc = std::allocator<bool>; std::vector<bool, _Alloc>::size_type = long unsigned int]'
  808 |       assign(size_type __n, const bool& __x)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_bvector.h:808:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/10/bits/stl_bvector.h:815:2: note: candidate: 'template<class _InputIterator, class> void std::vector<bool, _Alloc>::assign(_InputIterator, _InputIterator) [with _InputIterator = _InputIterator; <template-parameter-2-2> = <template-parameter-1-2>; _Alloc = std::allocator<bool>]'
  815 |  assign(_InputIterator __first, _InputIterator __last)
      |  ^~~~~~
/usr/include/c++/10/bits/stl_bvector.h:815:2: note:   template argument deduction/substitution failed:
Main.cpp:93:20: note:   candidate expects 2 arguments, 1 provided
   93 |    visited.assign(n);
      |                    ^
In file included from /usr/include/c++/10/vector:68,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from Main.cpp:1:
/usr/include/c++/10/bits/stl_bvector.h:829:7: note: candidate: 'void std::vector<bool, _Alloc>::assign(std::initializer_list<bool>) [with _Alloc = std::allocator<bool>]'
  829 |       assign(initializer_list<bool> __l)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_bvector.h:829:37: note:   no known conversion for argument 1 from 'long long int' to 'std::initializer_list<bool>'
  829 |       assign(initializer_list<bool> __l)
      |              ~~~~~~~~~~~~~~~~~~~~~~~^~~