Now we will do q operations on this graph. The i-th operation is represented by an integer. In i-th operation, if there are no vertices belong to group. , nothing happens. Otherwise,for all vertices belong to a group which is connected to. Now you are also given the q operations. Please answer each vertex belongs to which group after all operations.
You are given a graph containing n vertices and m edges. Vertices are numbered from 0 to n-1. Initially, vertex i belongs to group i. We define a group A is connected to group B if and only if there exists at least an edge that connects the two vertices which belong to A and B respectively. Now we will do q operations on this graph. The i-th operation is represented by an integer o_i o i . In i-th operation, if there are no vertices belong to group o_i o i , nothing happens. Otherwise, for all vertices belong to a group which is connected to o_i o i , those vertices will belong to group o_i o i after this operation. Now you are also given the q operations. Please answer each vertex belongs to which group after all operations.