Few small remarks.
When you write the following:

for (Pair p : pairs) {
You are creating a copy of each pair in the vector. In your case, those copies are not that expensive, but it's good to...