Question: solve it using c++ language, and with using DFS function In a social networking site, people are connected with other people. The whole system appears

In a social networking site, people are connected with other people. The whole system appears as a giant connected graph. In this question, you are required to answer the total number of people connected at t nodes away from each other (t distance connectivity). For example: Two persons directly connected are at 1 distance connectivity. While the two persons having a common contact without having direct connectivity, are at 2 distance connectivity. Input Format First line of input line contains, two integers n and e, where n is the nodes and e are the edges. Next e lines will contain two integers u and v meaning that node u and node v are connected to each other in undirected fashion. Next line contains single integer, m, which is number of queries. Next m lines, each have two inputs, one as source node and other as a required t distance connectivity which should be used to process query. Output Format Print a single integer represents the total number of people connected at t nodes away from the source Explanation After creating the graph, there was 3 queries, i. Source node: 4 , and we have to find out total number of nodes at a distance of 2 from node 4. 1(4>2>1),8(4>7>8),9(4>7>9),6(4>7>6)=4 ii. Similarly as above iii. Source node: 2 , and we have to find out total number of nodes at a distance of 1 from node 2 . 1(2>1),4(2>4),3(2>3)=3
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
