Please use python and python file i/o to solve the problem. Create an input file input3_1.txt as shown below, solve the problem and print the output to output3_1.txt file as shown in the question. Sample Input Explanation: In sample input 2, Query 0: Initially, there are 8 people in the village who do not know each other. {1} {2} {3} {4} {5} {6} {7} {8} Query 1: After person 2 and person 4 becoming friends: {1} {2,4} {3} {5} {6} {7} {8} The output is 2, since the size of the friends circle {2,4} is 2. Query 2: After person 4 and person 5 becoming friends: {1} {2,4,5} {3} {6} {7} {8} The output is 3, since the size of the friends circle {2,4,5} is 3. Query 3: After person 3 and person 6 becoming friends: {1} {2,4,5} {3,6} {7} {8} The output is 2, since the size of the friends circle {3,6} is 2. Query 4: After person 4 and person 7 becoming friends: {1} {2,4,5,7} {3,6} {8} The output is 4, since the size of the friends circle {2,4,5,7} is 4. Query 5: After person 3 and person 1 becoming friends: {2,4,5,7} {1,3,6} {8} The output is 3, since the size of the friends circle {1,3,6} is 3. Query 6: Since the person 2 and person 7 are already in the same friend circle, nothing changes: {2,4,5,7} {1,3,6} {8} The output is 4, since the size of the friends circle {2,4,5,7} is 4. Query 7: After person 6 and person 2 becoming friends: {1,2,3,4,5,6} {7} {8} The output is 7, since the size of the friends circle {1,2,3,4,5,6} is 7.
Please use python and python file i/o to solve the problem. Create an input file input3_1.txt as shown below, solve the problem and print the output to output3_1.txt file as shown in the question.
Sample Input Explanation:
In sample input 2,
Query 0: Initially, there are 8 people in the village who do not
know each other.
{1} {2} {3} {4} {5} {6} {7} {8}
Query 1: After person 2 and person 4 becoming friends:
{1} {2,4} {3} {5} {6} {7} {8}
The output is 2, since the size of the friends circle {2,4} is
2.
Query 2: After person 4 and person 5 becoming friends:
{1} {2,4,5} {3} {6} {7} {8}
The output is 3, since the size of the friends circle {2,4,5} is
3.
Query 3: After person 3 and person 6 becoming friends:
{1} {2,4,5} {3,6} {7} {8}
The output is 2, since the size of the friends circle {3,6} is
2.
Query 4: After person 4 and person 7 becoming friends:
{1} {2,4,5,7} {3,6} {8}
The output is 4, since the size of the friends circle {2,4,5,7}
is 4.
Query 5: After person 3 and person 1 becoming friends:
{2,4,5,7} {1,3,6} {8}
The output is 3, since the size of the friends circle {1,3,6} is
3.
Query 6: Since the person 2 and person 7 are already in the same
friend circle, nothing changes:
{2,4,5,7} {1,3,6} {8}
The output is 4, since the size of the friends circle {2,4,5,7}
is 4.
Query 7: After person 6 and person 2 becoming friends:
{1,2,3,4,5,6} {7} {8}
The output is 7, since the size of the friends circle
{1,2,3,4,5,6} is 7.
Step by step
Solved in 3 steps with 1 images