This is the problem:
I have n points (p1, p2, p3, .. pn), each of them can connect to any other with a determined cost x.
Each point belongs to one of a set of p
As far as I understand your question you need a shortest path in a directed graph. http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm should give you an idea.
regards, Jan