Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
934 B
1
Indexable
Never
void PlanningSportsCompetitions(const std::vector<SportsCompetition>& sportsCompetitions, std::unordered_map<uint16_t, std::vector<uint16_t>>& enrollments)
{
	std::vector<uint16_t> sportsIndex;
	std::unordered_map<uint16_t, bool> adjacent;
	std::priority_queue<std::pair<uint16_t, uint16_t>, std::vector<std::pair<uint16_t, uint16_t>>, std::greater<std::pair<uint16_t, uint16_t>>> q;

	for (const auto& pair : enrollments)
		q.push(std::make_pair(pair.second.size(), pair.first));

	while (!q.empty())
	{
		auto p = q.top();
		q.pop();
		uint16_t index = p.second;
		if (!adjacent[index])
		{
			sportsIndex.push_back(index);
			for (auto neighbor : enrollments[index])
				adjacent[neighbor] = true;
		}
	}
	std::cout << "The sports competitions that can be organized are: ";
	for (const auto& index : sportsIndex)
		std::cout << sportsCompetitions[index - 1] << ", ";
	std::cout << std::endl << std::endl;
}