#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) ) ;
}
I2luY2x1ZGUgPHV0aWxpdHk+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxtYXA+CiNpbmNsdWRlIDxpb3N0cmVhbT4KCnVzaW5nIGNvb3JkcyA9IHN0ZDo6cGFpcjxpbnQsaW50PiA7CnVzaW5nIGxpbmUgPSBzdGQ6OnBhaXI8Y29vcmRzLGNvb3Jkcz4gOyAvLyBzdGFydC1lbmQgY29vcmRpbmF0ZXMKCnN0ZDo6dmVjdG9yPGxpbmU+IHJlbW92ZV9wYWlyc193aXRoX3RoZV9zYW1lX2Rlc3RpbmF0aW9uKAogICAgICAgICAgICAgICAgICAgICAgICBjb25zdCBzdGQ6OnZlY3RvcjxsaW5lPiYgc3JjZV9kZXN0X3BhaXJzICkKewogICAgc3RhdGljIGNvbnN0IGF1dG8gY29tcGFyZV9kZXN0ID0gW10gKCBjb25zdCBsaW5lJiBhLCBjb25zdCBsaW5lJiBiICkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICA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