I have this graph problem I'm not sure how to approach.
I have an undirected graph with N vertices numbered 1-N. Every vertex numbered i has an arbitrary "rank" that can be anywhere from 1-i. Multiple vertices can have the same rank.
When traversing the graph, any vertex with rank r can instantly teleport/traverse to another vertex with the same rank r. This means unconnected components are still "connected" if at least one vertex from component A has the same rank as a vertex from component B.
How do I calculate the minimum amount of vertices needed to traverse from vertex A to vertex B?
My very naive solution is to add every edge that connects every equal-ranked vertex together to the graph, then applying a standard path-finding algorithm. This has a ridiculously long time complexity but I can't figure out a more efficient way to solve this.
Any help please?