Even Number Of Hops

You have an unweighted undirected graph of 200,000 accounts and 800,000 follow relationships. For a pair (s, t) you need the shortest walk from s to t that uses an even number of edges. Repeating a vertex is allowed. Plain BFS reports 7 edges, which is odd, so it is not an answer to this question.

What do you run BFS on instead?

A

BFS from s and a second BFS from t, then over all vertices m take the smallest d_s(m) + d_t(m) whose value is even.

B

A graph with two copies of every account, (v, 0) and (v, 1). Each original edge u-v becomes (u,0)-(v,1) and (u,1)-(v,0). BFS from (s,0), read the distance at (t,0).

C

Plain BFS on the original graph, but accept t only when the current layer index is even, and report the first even layer that contains it.

D

Plain BFS on the original graph. If d(t) comes back odd, step from t to any neighbour and back, which makes the walk even.