Submission #794629

#TimeUsernameProblemLanguageResultExecution timeMemory
794629Pablo_NoSplit the Attractions (IOI19_split)C++17
Compilation error
0 ms0 KiB
#include "split.h"

#include <algorithm>
#include <vector>

using namespace std;

const int N = 1e5+5;

int used[N];

int gn, ga, gb, gc;

vector<int> g[N];
vector<int> g2[N];

int pv, pu, pw;

int dfs(int v, int p)
{
	used[v] = true;

	vector<pair<int, int>> sts;
	
	int ts = 1;

	for(int u : g[v]) if(!used[u])
	{
		g2[u].push_back(v);
		g2[v].push_back(u);
		int x = dfs(u, v);
		sts.push_back({x, u});

		ts += x;
	}

	if(p != -1)
		sts.push_back({gn-ts, p});

	sort(sts.begin(), sts.end());

	auto pt = lower_bound(sts.begin(), sts.end(), pair<int, int>(ga, -1));

	if(pt != sts.end() && (gn-pt->first) >= gb)
	{
		pv = v;
		pu = pt->second;
		pw = 2;
	}

	pt = lower_bound(sts.begin(), sts.end(), pair<int, int>(gb, -1));

	if(pt != sts.end() && (gn-pt->first) >= ga)
	{
		pv = v;
		pu = pt->second;
		pw = 1;
	}

	return ts;
}

vector<int> res;
int used2[N];
int rem = 0;
void dfs2(int v, int c)
{
	used2[v] = true;

	if(rem)
	{
		res[v-1] = c;
		rem--;
	}

	for(int u : g2[v]) if(!used2[u])
		dfs2(u, c);
}

vector<int> find_split(int n, int a, int b, int c, vector<int> p, vector<int> q) {
	
	res.assign(n, 3);
	vector<int> cs(3);
	cs[1] = a;
	cs[2] = b;

	gn = n;
	ga = a, gb = b, gc = c;

	for(int i = 0; i < p.size(); i++)
	{
		g[p[i]].push_back(q[i]);
		g[q[i]].push_back(p[i]);
	}

	pv = -1;
	dfs(1, -1);

	if(pv == -1)
	{
		res.assign(n, 0);
		return res;
	}

	used2[pu] = true;
	rem = cs[pw];
	dfs2(pv, pw);

	used2[pu] = false;
	rem = cs[3-pw];
	dfs2(pu, 3-pw);

	return res;
}
////////////////////
#include <cstdio>
#include <cassert>

using namespace std;

int main() {
	int n, m, a, b, c;
	assert(5 == scanf("%d%d%d%d%d", &n, &m, &a, &b, &c));
	vector<int> p(m), q(m);
	for (int i=0; i<m; i++)
		assert(2 == scanf("%d%d", &p[i], &q[i]));
	fclose(stdin);

	vector<int> result = find_split(n, a, b, c, p, q);

	for (int i=0; i<(int)result.size(); i++)
		printf("%s%d", ((i>0)?" ":""), result[i]);
	printf("\n");
	fclose(stdout);
	return 0;
}

Compilation message (stderr)

split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:90:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |  for(int i = 0; i < p.size(); i++)
      |                 ~~^~~~~~~~~~
/usr/bin/ld: /tmp/ccq6yxTE.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccplhvoF.o:split.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status