Submission #1047377

#TimeUsernameProblemLanguageResultExecution timeMemory
1047377vjudge1Split the Attractions (IOI19_split)C++17
0 / 100
491 ms1048576 KiB
#include "split.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ff first
#define all(x) x.begin(), x.end()
#define ss second
const int N = 5e5;

int n;
vector<int> g[N];
vector<int> res;
vector<bool> vis;
int par[N];
void fill(int v, int par, int col, int colnum){
	queue<int> q;
	q.push(v);
	vis[v] = 1;
	vis[par] = 1;
	while(!q.empty()){
		int v = q.front();
		q.pop();
		// cout << v << ' ' << a << ' ' << b << ' ' << c << '\n';
		if(colnum > 0){
			res[v] = col;
			--colnum;
			// cout << v << ' ' << 2 << '\n';
		}
		for(int u: g[v]){
			if(!vis[u]){
				vis[u] = 1;
				q.push(u);
			}
		}
	}
	vis[par] = 0;
}

int sz[N];
void dfs(int v, int p){
	sz[v] = 1;
	par[v] = p;
	for(int u: g[v]){
		if(u != p){
			dfs(u, v);
			sz[v] += sz[u];
		}
	}
}

vector<int> find_split(int nn, int a, int b, int c, vector<int> Y, vector<int> X) {
	n = nn;
	res.resize(n+1);
	vis.resize(n+1);
	for(int i = 0; i < Y.size(); ++i){
		g[Y[i]].pb(X[i]);
		g[X[i]].pb(Y[i]);
	}


	dfs(0, n);

	vector<pair<int, int>> arr;
	arr.pb({a, 1});
	arr.pb({b, 2});
	arr.pb({c, 3});
	sort(all(arr));


	bool ok = 0;
	for(int i = 1; i < n; ++i){
		if(sz[i] >= arr[0].ff && sz[0] - sz[i] >= arr[1].ff){
			fill(i, par[i], arr[0].ss, arr[0].ff);
			fill(0, par[0], arr[1].ss, arr[1].ff);
			ok = 1;
			break;
		}else if(sz[i] >= arr[1].ff && sz[0] - sz[i] >= arr[0].ff){
			fill(i, par[i], arr[1].ss, arr[1].ff);
			fill(0, par[0], arr[0].ss, arr[0].ff);
			ok = 1;
			break;
		}
	}
	if(!ok) return res;

	for(int &cc: res) if(cc == 0) cc = 3;

	return res;
}

Compilation message (stderr)

split.cpp: In function 'std::vector<int> find_split(int, int, int, int, std::vector<int>, std::vector<int>)':
split.cpp:56:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |  for(int i = 0; i < Y.size(); ++i){
      |                 ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...