BFS+MST
因为题目里说"Whenever an alien is assimilated, or at the beginning of the search, the group may split in two or more groups",就是说只有在有'A'的地方他的意识才可以分裂.
所以先用BFS求出每个'A'到其他所有'A'的最短距离(把自己'S'也看成'A').然后以每个'A'为结点,两点间最短距离为边权构造图G,求出G的最小生成树就好.
BFS+MST
因为题目里说"Whenever an alien is assimilated, or at the beginning of the search, the group may split in two or more groups",就是说只有在有'A'的地方他的意识才可以分裂.
所以先用BFS求出每个'A'到其他所有'A'的最短距离(把自己'S'也看成'A').然后以每个'A'为结点,两点间最短距离为边权构造图G,求出G的最小生成树就好.