Tour through Barcelona

0

0 votes
Hard
Problem

Mr. M and Mr. K decided to take a tour of the city of Barcelona. There are N junctions and M roads connecting these junctions in Barcelona. Mr. M starts tour from junction X and Mr. K starts from junction Y. Both will end their tour at junction Z. None of the two will go through same road twice. Both of them were given a task of putting a banner of Endurance in the middle of each road (one banner per road) they go through. Mr. M has blue coloured banners and Mr. K has red coloured banners. They want to know the minimum possible number of roads which will have both blue and red coloured banners at the end of their tours for given X, Y and Z.

Input Format :

First line will contain three integers N (number of junctions) and M (number of roads) and Q (number of queries). Next M lines will contain two integers U and V denoting a road between junction U and junction V. Next Q lines contains three integers - X (starting junction for Mr. M) , Y (starting junction for Mr. K) and Z (destination junction).

Output Format :

For each query print the number of roads with two banners.

Constraints :

  • 1<=N<=105
  • 1<=M<=105
  • 1<=Q<=105
  • 1<=U,V,X,Y,Z<=N

Setter : Tanmay Patel

Time Limit: 1.5
Memory Limit: 256
Source Limit:
Editor Image

?