#K90532. Friendship Group in Social Network
Friendship Group in Social Network
Friendship Group in Social Network
Given a social network consisting of (n) individuals and (m) bidirectional friendship connections, determine whether two specified individuals, (x) and (y), are in the same friendship group. Two individuals belong to the same group if there is a path connecting them through a sequence of friendship connections. This graph problem can be solved using breadth-first search (BFS) or union-find data structures. The input is provided via standard input and the output should be produced to standard output.
inputFormat
The first line contains two space-separated integers (n) and (m), representing the number of individuals and the number of friendship connections respectively. The next (m) lines each contain two integers (u) and (v), indicating a bidirectional friendship connection between individuals (u) and (v). The last line contains two integers (x) and (y), the individuals to be checked.
outputFormat
Output a single word: "yes" if individuals (x) and (y) are in the same friendship group, otherwise "no".## sample
5 4
1 2
2 3
4 5
3 5
1 5
yes