Sounds like the job for a Graph data structure.
Graph (abstract data type) - Wikipedia, the free encyclopedia