Wednesday, February 28, 2018

UVa problem solution 11503 - Virtual Friends

problem link:

Discuss: you can solve this problem by simply using disjoint set. just rank the set. and print for every new element. and there is no tricky part. you can use map for using  number instead of string.

try yourself, before see the code



UVa problem solution 10685 - Nature

problem link:

Discuss: you can simply solve this problem using disjoint set. just rank the set by counting the number of element in the set. and you can also use map for using number instead of string. and there is no tricky part in this problem.

try yourself before see the code



UVa problem 459 - Graph Connectivity


problem link:

Discuss: you can solve this problem in many ways like dfs,bfs, disjoint set. i used here disjoint set.just simply put the array element in vector and then erase every duplicate element for in similar set only number exist in vector. the i just count the number of element in the vector. there is also a case where no connectivity among nodes. if use scanf for scan newline than on that case it will not give you any output. so where any problem if need to scan a line only than use getchar() instead of scanf. and there is no more tricky part in this problem.


try your self, before see the code



Saturday, February 24, 2018

UVa problem solution 10608 - Friends

problem link:

Discuss: this is simple disjoint set problem. to solve this problem just use a extra array to store how much element add in a set. for that in make in makeUnion function when you check is the parent to node equal or not.then if not equal then you set ara[x]=y similar way we just count the member of the set also.such m[y]+=m[x] and just print the biggest element of the m array.there is no tricky part in this problem