Getting a path from list of arcs in C++
The key is to create a mapping for the edges:

vector&lt;int&gt;
get_pretty_path(const vector&lt;pair&lt;int,int&gt;&gt;&amp; edges, int s, int t) {
    map&lt;int,int&gt; edgeMap = {begin(edges), end(edges)};
    vector&lt;int&gt; path;
    while (s != t) {
        path.push_back(s);
        s = edgeMap[s];
    }
    path.push_back(s);
    return path;
}
int main() {
    const vector&lt;pair&lt;int,int&gt;&gt; edges{{4, 5}, {7, 4}, {2, 3}, {5, 2}};
    const vector&lt;int&gt; path = get_pretty_path(edges, 7, 3);
    for (auto i : path) {
        cout &lt;&lt; i &lt;&lt; ' ';
    }
    cout &lt;&lt; endl;
    return EXIT_SUCCESS;
}


The code assumes using namespace std; which is sometimes frowned
upon but which I think is fine for small examples. The code will bug
out if you can't walk from s to t or if more than one edge starts
at a given node index. If such situations can happen, you have to decide
how to best handle them.