#K14666. Photo Tag Intersections
Photo Tag Intersections
Photo Tag Intersections
You are given a collection of photos, each associated with a set of integer tags. Your task is to determine the number of common tags for every distinct pair of photos. For each pair ( (i, j) ) where ( i < j ) (with photos numbered starting from 1), you must compute the size of the intersection of their tag sets.
Details:
- The first input line contains an integer \( n \), representing the number of photos.
- Each of the following \( n \) lines begins with an integer \( k \), the number of tags in that photo, followed by \( k \) space-separated integers denoting the tags.
Output: For every pair of photos ( (i, j) ) with ( i < j ), output a line with three space-separated integers: ( i ), ( j ), and the number of tags common to both photos.
inputFormat
Input is read from standard input (stdin). The first line contains an integer ( n ) denoting the number of photos. Each of the next ( n ) lines starts with an integer ( k ) (the number of tags for that photo) followed by ( k ) space-separated integers representing the tags.
outputFormat
For each pair of photos ( (i, j) ) with ( i < j ), print a single line with three integers: ( i ), ( j ), and the count of shared tags. The pairs should be output in order of increasing first index and, for a given first index, in increasing second index.## sample
3
2 1 2
3 2 3 4
2 1 4
1 2 1
1 3 1
2 3 1
</p>