Building a map, calculating distance on it

Hello.
I am studying for informatic olimpics.

In a question I need to build a map and be able to tell distance between buildings.

For example, a city map would be like this:

Map.jpg:[URL=http://imageupload.org/en/file/211336/map.jpg.html][IMG]http://imageupload.org/thumb/thumb_211336.jpg[/IMG][/URL]

The numbers represents buildings. The lines between numbers represents roads.

The input would be like this:

count of buildings, count of roads

9 10

initial building for the road, last building for the road

1 2
2 3
2 4
4 3
4 7
7 9
9 8
8 5
5 3
5 6

I tried to struct nodes, and make lists(arrays) of available roads.

But I couldn't change the count of roads for a building because ISO c++ forbids the change.

What else can I use to build these maps and Can I find the distance(count of roads)between two buildings?


If you use std::vector (or some other container class) instead of arrays it will be much easier to resize the number of elements.

To get the shortest distance between two buildings you can use Dijkstra's algorithm.
Thanks for the help. I succesfully created the city map.

But, I may need some more help.

The real task on the map is that:

We have 2 different person at different places. The building IDs will be entered by user.

these two persons have different goals(buildings to go). There is a restriction. these two person cannot get closer more than a distance(entered by user).

With given 2 initial bulding IDs and 2 goals and 1 restriction, the program must tell us that, may the goals be achieved or not.

for the map that I had given before examples are here.

"restriction" is 3 road distance.

---------initial coordinates-----------------------goals---
ex1.-------------- 1 -------------------------------> 4
Achieved -------- 9 ------------------------------> 8

ex2. -------------- 7 -------------------------------> 3
Achieved----------6-------------------------------> 9

ex3.--------------- 7 -------------------------------> 9
Failed------------6---------------------------------> 3
Topic archived. No new replies allowed.