Use sets instead of unordered pairs to avoid C++11.