I have this task: Given n vertices, that are connected each to the next and previous, forming a railway like: 1--2--3--4...
Given a set of edges in the form of i -> j, and the edge can go either north of the railway, or south, the question is whether you can build the given edges (each either north or south of the railway) so that no two edges intersect?
My idea was with backtracking checking each of the given pairs first going north, and then going south combined with a matrix A where I keep if the edge from i to j (A[i][j]) is build north or south, and determine if I can build the next one so that it is not intersecting the precious ones, but it was too slow. Is there an existing algorithm that does what I want or can you help me with it?