#C8021. Count Distinct Years Accessed
Count Distinct Years Accessed
Count Distinct Years Accessed
You are given an integer \(m\) representing the total number of available years and an integer \(n\) representing the number of queries. Each query consists of two integers \(y_1\) and \(y_2\), which denote two years. Imagine you travel back and forth between these two years repeatedly. Regardless of how many times you travel between them, only the years \(y_1\) and \(y_2\) are accessed.
Your task is to determine and print the number of distinct years accessed for each query. Note that if \(y_1 = y_2\), then only one distinct year is accessed; otherwise, exactly two distinct years are accessed.
inputFormat
The input is read from stdin
and is structured as follows:
- The first line contains an integer \(m\), which is the total number of available years (this value may not directly affect the result).
- The second line contains an integer \(n\), the number of queries.
- The next \(n\) lines each contain two space-separated integers \(y_1\) and \(y_2\) representing a query.
outputFormat
For each query, output a single line with the number of distinct years accessed. Each result should be printed on a new line to stdout
.
6
3
1 3
2 5
4 6
2
2
2
</p>