Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

solve it using c++ language, and with using DFS function image text in transcribed
image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Which costs are relevant to special-order decisions?

Answered: 1 week ago