EIMAXGRP - Same Value Vertices
Xem dạng PDFYou are given an undirected graph with n vertices labeled from 0 to n-1.
Each vertex has an associated integer value.
Two vertices belong to the same group if:
- They are connected through a path in the graph
- All vertices along the path have the same value
The largest group is the group having the maximum number of vertices.
Your task is finding the largest group and print the list of vertices belonging to that group.
Input
The first line consists of two positive integers are the number of vertices n and the number of edges m (0 < n, m < ~10^{5}~)
The second line consists of n positive integers v[i] representing the corresponding value of vertex i-th (0 ≤ i < n, 1 ≤ v[i] ≤ n)
Then there are m lines, each containing two integers a and b representing the connection between a and b (0 ≤ a, b < n)
Output
Print the list of vertices separated by spaces. If there are more than one largest group, you only need to print one of them.
Example
Input
7 5
1 1 2 2 2 1 1
0 1
1 5
3 6
2 3
3 4
Output
0 1 5
Another output:
2 3 4
Bình luận