#C11333. Maximum Unique Crops

    ID: 40638 Type: Default 1000ms 256MiB

Maximum Unique Crops

Maximum Unique Crops

You are given N fields and M bidirectional connections between these fields. Each field is planted with a crop denoted by an integer. A group of connected fields forms a connected component of the graph. Your task is to determine the maximum number of unique crops that can be collected from any single connected component.

More formally, let \(N\) be the number of fields and \(M\) be the number of connections. Each field \(i\) (1-based index) has a crop type \(c_i\). A connection between fields \(a\) and \(b\) indicates that they are directly linked. A connected component is a subset of fields where every field is reachable from any other field in the same component. You need to find the maximum unique crop count among all connected components.

Input Constraints:

  • \(1 \leq N \leq 10^5\)
  • \(0 \leq M \leq 10^5\)
  • Crop types are integers.

Example:

Input:
6 5
1 2
2 3
3 4
4 5
5 6
1 2 3 4 5 6

Output: 6

</p>

inputFormat

The input is given from standard input (stdin) and has the following format:

N M
u1 v1
u2 v2
... (M lines total)
c1 c2 c3 ... cN

where:

  • N, M: number of fields and connections.
  • Each of the next M lines contains two integers \(u_i\) and \(v_i\) indicating a bidirectional connection between fields \(u_i\) and \(v_i\).
  • The last line contains N integers; the i-th integer represents the crop type of the i-th field.

outputFormat

Output a single integer, which is the maximum number of unique crops in any connected component. The output should be written to standard output (stdout).

## sample
6 5
1 2
2 3
3 4
4 5
5 6
1 2 3 4 5 6
6