This problem falls under the LCA category in Csacademy's tasks list.
How to apply LCA when given graph may not be a tree?
As I've understood it, to answer a given query of two vertices namely A and B, we have to find the number vertices which are present in all the paths from vertex A to vertex B.
Links to similar problems would be appreciated. Thanks!!