0

I have to find shortest path and chose BFS, but nodes are described in x,y coordinates. Input data:

3 9

1 6

2 3 8

2 5 7

First two numbers are height and width, then first number in each row describes how many points in that row and other are x coordinates of point in given row. I need to create an array with connection map. I get those numbers and push them into queues.

cin >> n >> x;

for(auto i=0;i<n;i++)
{
    cin >> k;
    for(auto j=0;j<k;j++)
    {
        cin >> a;
        s[I].push(a);
    }
    
    
}

In this example the first node would be point [2,3], second [3,5] third [1,6],fourth [3,7] fifth [2,8] etc. Node gets a connection with another only if it is to its right (one way graph) and it connects to first node of each row, int this example first would connect to second, third and fifth. edges[1]={2,3,5} I think each node except last connects to (number of rows) nodes, her it is 3; How can I rewrite them to get edge vector "edges" with all connections?

  • How do you measure "distance" between two nodes? Is it Euclidean distance or Manhattan distance or something else? – Code-Apprentice Oct 29 '20 at 15:44
  • Step one is to rewrite your input into a collection of (x,y) pairs, then apply the edges between all nodes in a row, finally connect the first node of each row. Somehow. – Botje Oct 29 '20 at 15:46
  • @Code-Apprentice Distance is always 1, because i calculate how many nodes is in between first node and last. – BananaBread Oct 29 '20 at 15:59
  • I suggest you break this into smaller steps. You need to build the graph before you worry about BFS or shortest path. First, you need to parse the file and create a list of coordinate pairs. – Code-Apprentice Oct 29 '20 at 16:32
  • @Code-Apprentice So I created x,y pairs but how to create edges? – BananaBread Oct 29 '20 at 17:13
  • @BananaBread What are the rules? When are two nodes adjacent to each other? – Code-Apprentice Oct 29 '20 at 17:21
  • I don't understand the ".. then first number in each row describes how many points in that row and other are x coordinates of point in given row" Can you clarify that one? – Totte Karlsson Oct 29 '20 at 18:10
  • @TotteKarlsson So numbers are given in rows specified by N, then first number (in this example the are 1,2,2) describes how many numbers I need to get in in this row - 1 in second row of input means that there is 1 number in first row, then i cin that cords (6) – BananaBread Oct 29 '20 at 18:42
  • @Code-Apprentice each node connects to (numbers of rows) nodes - one in each row. It connect to first node to the right (x+) in every row and so on. It can't connect to the left or up/down, but nodes never have same x coordinate. – BananaBread Oct 29 '20 at 18:44
  • @BananaBread So you need to iterate through each node and find all of the connections from that node to other nodes. For a given node at `(x, y)`, describe the steps you can take to find those connections. – Code-Apprentice Oct 29 '20 at 22:44

0 Answers0