Sensei,

I think a simple solution is to use a counter.

int Count = 0;

for(std::size_t v = source_node; ; v = p[v])
{
    Count++;

    if (Count > Distance)
    {
         break;
    }
}