Programma completo
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <map>
#include <memory>
using namespace std;
class Parola
{
public:
	Parola(const std::string & str = "")
		: m_string(str)
		, m_hash(funzHash(str))
	{
	};
	const int GetHash() const { return m_hash; };
	const std::string & GetString() const { return m_string; };
	static const int funzHash(const std::string & parolaHash)
	{
		int h = 5381;
		const size_t size = parolaHash.size();
		for (size_t i = 0; i < size; ++i)
		{
			h = h * 33 + parolaHash[i];
		}
		h = abs(h);
		return h;
	}
private:
	std::string m_string;
	int m_hash;
};
class Gruppi
{
	std::map<int, Parola> gruppoParole;
public:
	Gruppi(const int _id) : m_ID(_id) , m_globalSize(0){};
	~Gruppi(){};
	const int GetGroupID() const { return m_ID; };
	const size_t GetGroupSize() const { return gruppoParole.size(); };
	const size_t GetGroupGlobalSize() const { return m_globalSize; };
	const void SetGroupID(const int & groupID){ m_ID = groupID; };
	std::map<int, Parola> & GetGruppo() { return gruppoParole; };
	const bool InserisciParola(const std::string & parola)
	{
		const int hash = Parola::funzHash(parola);
		std::map<int, Parola>::const_iterator it = gruppoParole.find(hash);
		if (it == gruppoParole.end())
		{
			Parola nuovaParola(parola);
			gruppoParole[hash] = nuovaParola;
			m_globalSize += parola.size();
			return true;
		}
		return false;
	}
	const bool InserisciParola(const Parola & parola)
	{
		std::map<int, Parola>::const_iterator it = gruppoParole.find(parola.GetHash());
		if (it == gruppoParole.end())
		{
			gruppoParole[parola.GetHash()] = parola;
			m_globalSize += parola.GetString().size();
			return true;
		}
		return false;
	}
	const bool CercaParola(const std::string & parola)
	{
		return CercaParola(Parola::funzHash(parola));
	}
	const bool CercaParola(const int & parolaHash)
	{
		return (gruppoParole.find(parolaHash) != gruppoParole.end());
	}
	const bool EliminaParola(const std::string & parola)
	{
		return EliminaParola(Parola::funzHash(parola));
	}
	const bool EliminaParola(const int & parolaHash)
	{
		std::map<int, Parola>::const_iterator it = gruppoParole.find(parolaHash);
		if (it != gruppoParole.end())
		{
			m_globalSize -= it->second.GetString().size();
			gruppoParole.erase(it);
			return true;
		}
		return false;
	}
	const void UnisciGruppo(Gruppi & gruppo)
	{
		m_globalSize += gruppo.GetGroupGlobalSize();
		std::map<int, Parola> &g = gruppo.GetGruppo();
		gruppoParole.insert(g.begin(), g.end());
	}
	void Svuota()
	{
		gruppoParole.clear();
		m_globalSize = 0;
	}
private:
	int m_ID;
	size_t m_globalSize;
};
int main()
{
	std::vector<Gruppi *> vettoreGruppi;
	std::map<int, Gruppi *> mapHash;
	
	string input, parola, parola2;
	int dimCoda = 0, b = 0;
	char s;
	while (input != "<END>")    
	{
		getline(cin, input);
		stringstream ssin(input);
		s = 0, parola = "", parola2 = "";
		ssin >> s;
		switch (s)
		{
			case 'e':
			{
				while (ssin >> parola)
				{
					Parola p(parola);
					if (mapHash.find(p.GetHash()) == mapHash.end())
					{
						Gruppi *g = new Gruppi(vettoreGruppi.size());
						if (g->InserisciParola(p))
						{
							mapHash[p.GetHash()] = g;
							vettoreGruppi.push_back(g);
						}
					}
					
				}
			}
			break;
			case 'u':
			{
				std::string s1, s2;
				ssin >> s1 >> s2;
				const int hash1 = Parola::funzHash(s1);
				const int hash2 = Parola::funzHash(s2);
				std::map<int, Gruppi *>::const_iterator it1, it2;
				it1 = mapHash.find(hash1);
				it2 = mapHash.find(hash2);
				if ((it1 != mapHash.end()) && (it2 != mapHash.end()))
				{
					it1->second->UnisciGruppo(*(it2->second));
					for (std::map<int, Gruppi *>::iterator it = mapHash.begin(); it != mapHash.end(); ++it)
					{
						if (it->second == it2->second)
						{
							it->second = it1->second;
						}
					}
					it2->second->Svuota();
				}
			}
			break;
			case 'm':
			{
						std::string s1, s2;
						ssin >> s1 >> s2;
						const int hash1 = Parola::funzHash(s1);
						const int hash2 = Parola::funzHash(s2);
						std::map<int, Gruppi *>::iterator it1;
						std::map<int, Gruppi *>::const_iterator it2;
						it1 = mapHash.find(hash1);
						it2 = mapHash.find(hash2);
						if ((it1 != mapHash.end()) && (it2 != mapHash.end()))
						{
							it2->second->InserisciParola(s1);
							it1->second->EliminaParola(s1);
							it1->second = it2->second;
						}
			}
			break;
			case 's':
			{
						std::string s1;
						ssin >> s1;
						const int hash1 = Parola::funzHash(s1);
						std::map<int, Gruppi *>::iterator it1;
						it1 = mapHash.find(hash1);
						if (it1 != mapHash.end())
						{
							std::cout << it1->second->GetGroupSize() << " - " << it1->second->GetGroupGlobalSize() << std::endl;
						}
			}
			break;
		}
	}
	return 0;
}
Prova e dimmi come va.
p.s.: Devi liberare la memoria allocata con new. Non ho avuto il tempo a farlo.