This is a nice problem because it can be solved in different ways - dynamic programming, maximum flow or bipartite matching.
The solution of the problem in one line would be
calculate maximum number of node disjoint paths from node p1 to p2 whose length is less than or equal to 3.