Question

1. (10 pts) Ginerva Weasley is playing with the network given below. Help her calculate the number of paths from node 1 to no

0 0
Add a comment Improve this question Transcribed image text
Answer #1

ANSWER:-

Run Debug Stop Share H Save Beautify Language C main.c 1 #include <bits/stdc++.h> 3 using namespace std 5 vector<int>adjlist[31 32 33 dp[adjlist[k][j]] +dp[k]; 34 35 if(visited[ adjlist[k][j]]-1) 36 38 39 q.push(adjlist[k][j]); 40 41 visited[adjlist[60 62 63 adjlist[u].push_back (v); 64 65 for (int 1-0; 1(15;i++) 67 68 70 71 visited[i]- 72 73 dp[i] ; 74 75 76 77 dp[1] 1; 7

OUTPUT SCREEN SHOT:-

9-- shortest.p 3 8 2 8 4 9 8 9 5 10 9 10 4 10 5 6 6 11 10 11 5 11 9 12 12 13 10 13 11 13 11 14 13 14 No of ways to 1 No of wa

COPY CODE:-

#include <bits/stdc++.h>

using namespace std;

vector<int>adjlist[20];

int visited[25];

int dp[25];

void bfs(int i)

{

queue <int> q;

q.push(i);

visited[i]=1;

while(!q.empty())

{

int k=q.front();

q.pop();

for(int j=0;j<adjlist[k].size();j++)

{

dp[adjlist[k][j]] += dp[k];

if(visited[adjlist[k][j]]!=1)

{

q.push(adjlist[k][j]);

visited[adjlist[k][j]]=1;

}

}

}

}

int main()

{

int u,v;

for(int i=0;i<24;i++)

{

cin>>u>>v;

adjlist[u].push_back(v);

}

for(int i=0;i<15;i++)

{

visited[i] = 0;

dp[i] = 0;

}

dp[1] = 1;

bfs(1);

for(int i=1;i<=14;i++)

cout<<"No of ways to "<<i<<" "<<dp[i]<<endl;

}

Add a comment
Know the answer?
Add Answer to:
1. (10 pts) Ginerva Weasley is playing with the network given below. Help her calculate the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Q1: Here we consider finding the length of the shortest path between all pairs of nodes...

    Q1: Here we consider finding the length of the shortest path between all pairs of nodes in an undirected, weighted graph G. For simplicity, assume that the n nodes are labeled 1; 2; : : : ; n, that the weight wij of any edge e = (i; j) is positive and that there is an edge between every pair of nodes. In this question, the goal is to solve this via dynamic programming. Note that the algorithm you will...

  • 1. Linear programming can be used to calculate the maximum flow in a network from the...

    1. Linear programming can be used to calculate the maximum flow in a network from the source s, to the sink t. Which of the following statements below gives the correct objective function, and number of constraints for applying a linear program for computing maximum flow in the following graph? In this graph, the maximum capacity of each edge is given as the number next to the corresponding edge. The flow along an edge eſi, j) is denoted by fij....

  • Computer Communication Networking 3. Given the following network with assigned weights (10 Points) 3 1 4...

    Computer Communication Networking 3. Given the following network with assigned weights (10 Points) 3 1 4 1 Using Dijkstra's algorithm, show shortest path from node u to node z. (Hint, make a table)

  • 1. (8 pts) Consider a network with the following topology. Unless indicated otherwise, all links have...

    1. (8 pts) Consider a network with the following topology. Unless indicated otherwise, all links have distance = 1. (a) Use the first four steps of using the Dijkistra shortest path algorithm to find the shortest paths from A to the rest of the nodes. (b) Let's assume the distance vector routing algorithm is used. At t = 0, each node only knows the distances to its neighbors. The distances to the other nodes will be set to infinity. Nodes...

  • The network below shows a network of railway lines from city 1 to city 10. The...

    The network below shows a network of railway lines from city 1 to city 10. The numbers on the arcs represent the number of cars per hour that can pass along that segment of track 400 600 300 150 500 200 400 600 450 10 6 300 300 300 200 300 500 500. 400 350 Find the maximal flow in cars per hour that can pass through the network from node 1 to node 10. In each blank, enter the...

  • 2. Given the table below (10 pts): A. Draw the project network B. Calculate the expected...

    2. Given the table below (10 pts): A. Draw the project network B. Calculate the expected time to complete each activity as well as the variance (or standard deviation) associated with that time C. Determine the time associated with each potential path and denote the critical path D. Given the calculated data, what is the probability of completing the project in 30 days? 35 days? E. If you were to try to improve your performance (in terms of time), what...

  • can anyone provide answers with explaination ? thanks a lot I. In the example of recycling...

    can anyone provide answers with explaination ? thanks a lot I. In the example of recycling the elements of a list in O1) time, which situation holds? A. Both lists are circular B. Both ists are not circular C. The list to be recycled is circular, the garbage list is not D. The garbage list is circular, the list to be recycled is not 2. What is the worst-case time to perform MINIMUML) for a sorted, doubly-linked list with nodes?...

  • Using C++ For a given electrical circuit, composed from a network ofresistors, arranged in parallel and/or...

    Using C++ For a given electrical circuit, composed from a network ofresistors, arranged in parallel and/or series, write a program to calculate the total resistance of the circuit. To facilitate user to define the network, by giving the network circuit formula in text, a notation is used, whereand 7" operators mean series and parallel layout respectively. Please note that parallel 'operator has higher precedence than seriesoperator Table below shows a few examples of circuit diagrams and their respective circuit formulas...

  • B. Resource Loading (33 pts). The network diagram below represents a project plan. a. b. C....

    B. Resource Loading (33 pts). The network diagram below represents a project plan. a. b. C. Compute the early, late, and slack times. Include your diagram in your paper What is the project duration? What is the critical path -illustrate it on your diagram (such as a dotted line). Ch 8 Assignment Resources: P(ainter); T(rimmer) 0 A START P & T ES ID EF SL Resour LS Dur LF 2 As your text stated, a plan isn't a schedule until...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT