#K49107. Longest Connected Subsequence

    ID: 28569 Type: Default 1000ms 256MiB

Longest Connected Subsequence

Longest Connected Subsequence

You are given a graph representing a set of villages. The villages are numbered from 1 to n and are associated with a string (each character represents a village, but the string is not used in computations). You are also given m bidirectional connections between villages. Your task is to determine the size of the largest connected component in the graph.

Note: Each connection is provided as a pair of 1-indexed integers. Even if there is no connection provided (m = 0), every village is considered isolated and hence the largest connected component will have size 1.

Input and output are read from standard input (stdin) and written to standard output (stdout) respectively.

Mathematical Formulation:

Let the graph be represented as G = (V, E) where V is the set of villages such that |V| = n and E is the set of m edges. Let C be a connected component of G. Find maxC⊆G|C|.

inputFormat

The input consists of several lines:

  1. The first line contains an integer n (1 ≤ n ≤ 105), the number of villages.
  2. The second line contains a string of length n, where each character represents a village.
  3. The third line contains an integer m (0 ≤ m ≤ 105), the number of connections.
  4. The next m lines each contain two space-separated integers a and b (1 ≤ a, b ≤ n) representing a bidirectional connection between the villages a and b.

outputFormat

Output a single integer that represents the size of the largest connected component in the given graph.

## sample
5
abcde
3
1 2
2 3
4 5
3