#include <utility>
#include <vector>
#include <map>
#include <iostream>
std::vector< std::pair<int,int> > remove_pairs_with_the_same_destination(
const std::vector< std::pair<int,int> >& srce_dest_pairs )
{
using pair = std::pair<int,int> ;
static const auto compare_dest = [] ( const pair& a, const pair& b )
{ return a.second < b.second ; } ;
std::map< pair, int, decltype(compare_dest) > counts(compare_dest) ;
for( const pair& p : srce_dest_pairs ) ++counts[p] ;
std::vector<pair> result ;
for( const auto& p : counts ) if( p.second == 1 ) result.push_back(p.first) ;
return result ;
}
int main()
{
std::vector< std::pair<int,int> > seq =
{ {0,2}, {1,2}, {3,4}, {5,6}, {0,1}, {7,2}, {0,3}, {8,6}, {9,2} } ;
for( const auto& p : remove_pairs_with_the_same_destination(seq) )
std::cout << p.first << ',' << p.second << '\n' ;
}
I2luY2x1ZGUgPHV0aWxpdHk+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxtYXA+CiNpbmNsdWRlIDxpb3N0cmVhbT4KCnN0ZDo6dmVjdG9yPCBzdGQ6OnBhaXI8aW50LGludD4gPiByZW1vdmVfcGFpcnNfd2l0aF90aGVfc2FtZV9kZXN0aW5hdGlvbigKICAgICAgICAgICAgICAgICAgICAgICAgY29uc3Qgc3RkOjp2ZWN0b3I8IHN0ZDo6cGFpcjxpbnQsaW50PiA+JiBzcmNlX2Rlc3RfcGFpcnMgKQp7CiAgICB1c2luZyBwYWlyID0gc3RkOjpwYWlyPGludCxpbnQ+IDsKCiAgICBzdGF0aWMgY29uc3QgYXV0byBjb21wYXJlX2Rlc3QgPSBbXSAoIGNvbnN0IHBhaXImIGEsIGNvbnN0IHBhaXImIGIgKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB7IHJldHVybiBhLnNlY29uZCA8IGIuc2Vjb25kIDsgfSA7CiAgICBzdGQ6Om1hcDwgcGFpciwgaW50LCBkZWNsdHlwZShjb21wYXJlX2Rlc3QpID4gY291bnRzKGNvbXBhcmVfZGVzdCkgOwogICAgZm9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