Given an undirected graph with n nodes labeled 0 to n - 1, an edge list edges, a starting node start, and a target node target, return the length of the shortest path from start to target. If no path exists, return -1. Implement an algorithm that works efficiently for large sparse graphs.
def shortest_path_length(n, edges, start, target):