HBC209389OperatingonaGraph题解

水水月牙 算法基础篇 58 0
想要检验自己的编程水平?来试试全网最全C++题库,让您在挑战中不断进步。
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.

HBC209389OperatingonaGraph题解
-第1张图片-东莞河马信息技术
(图片来源网络,侵删)
成为编程大师,不再是梦想!全网最全C++题库,助您开启编程新篇章。

标签: HBC209389OperatingonaGraph题解