I created a set of structure and sorted was manually. See the code...
class edge {
public:
int u, v, w;//variables on set
edge() {}
edge(int a, int b,int c) {
u = a;
v = b;
w = c;
}
bool operator < ( const edge& z ) const {
return w < z.w;//compare as your wish
}
};
set<edge> e;
Then tried to insert some element as u v w
1 2 10
1 3 8
3 2 3
1 4 3
1 3 6
2 1 2
But 1 4 3 didn't added. Then i used multiset and it worked . why?? we know set doesn't contain duplicate element. But there are no duplicate.
Well, your implementation of set thinks that different elements are the ones that differ only by w. And you already have an element with w = 3 in your set.
Oh yes, there are.
Take a look at your comparator:
As you can see, you take into account only the w value. So any two edges having the same w value are considered equal.