if input is 1,1 1,1 1,1 then why i need to insert 1,1 three times? basically im asking for how to check if this edges is already existed? please help me
You will not usually need to do that because problems do not provide duplicate edges as input (what’s the point?). But if you are facing such a situation, use std::set instead of std::vector to store the neighbours of a vertex. A set does not allow duplicate elements, so even if you insert the same value multiple times, the set will store only one copy.