#include <utility>
#include <vector>
#include <map>
#include <iostream>

using coords = std::pair<int,int> ;
using line = std::pair<coords,coords> ; // start-end coordinates

std::vector<line> remove_pairs_with_the_same_destination(
                        const std::vector<line>& srce_dest_pairs )
{
    static const auto compare_dest = [] ( const line& a, const line& b )
                                       { return a.second < b.second ; } ;
    std::map< line, int, decltype(compare_dest) > counts(compare_dest) ;
    for( const line& p : srce_dest_pairs ) ++counts[p] ;

    std::vector<line> result ;
    for( const auto& p : counts ) if( p.second == 1 ) result.push_back(p.first) ;

    return result ;
}

int main()
{
   std::vector<line> seq =
    { { {0,7}, {0,2} }, { {1,2}, {3,4} }, { {5,6}, {0,2} }, { {7,2}, {7,8} }, { {8,6}, {0,2} } } ;

   static const auto print = [] ( const std::vector<line>& sequence )
   {
        for( const auto& line : sequence )
            std::cout << line.first.first << ',' << line.first.second << " => "
                       << line.second.first << ',' << line.second.second << '\n' ;
   };

   print(seq) ;
   std::cout << "----------------\n" ;
   print( remove_pairs_with_the_same_destination(seq) ) ;
}
