#K15581. Check Similarity of Video Tags
Check Similarity of Video Tags
Check Similarity of Video Tags
You are given a collection of videos, each with a unique identifier and a set of associated tags. Two videos are considered similar if they share at least one common tag, i.e., if their tag sets have a non-empty intersection: $$A \cap B \neq \emptyset$$. You will be provided with a list of pairs of videos; for each pair, determine whether the two videos are similar.
For each pair, output "Similar" if the videos have at least one tag in common or "Not Similar" if they do not.
Make sure to read the input from standard input (stdin) and write your output to standard output (stdout).
inputFormat
The input is given in the following order:
- An integer
n
representing the number of videos. n
lines follow. Each line starts with an integer representing the video ID, followed by one or more strings representing its tags, separated by spaces.- An integer
m
representing the number of video pairs to check. m
lines follow, each containing two integers separated by a space, representing a pair of video IDs.
outputFormat
For each of the m
pairs, output a single line with either "Similar" if the videos share at least one common tag, or "Not Similar" if they do not.
3
1 comedy romance drama
2 action thriller comedy
3 horror thriller
2
1 2
1 3
Similar
Not Similar
</p>