301319: CF246D. Colorful Graph

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Colorful Graph

题意翻译

有N个点,每个顶点对应一种颜色,可以相同。给出连接这些顶点的M边,定义Q(k)是所有颜色为k的所有顶点相连的不同的颜色的总数量(不包含k),求使得Q(k)最大时的k的值,如果有多个k 值满足,输出最小的k值 感谢@Ricardo_Ni 提供的翻译

题目描述

You've got an undirected graph, consisting of $ n $ vertices and $ m $ edges. We will consider the graph's vertices numbered with integers from 1 to $ n $ . Each vertex of the graph has a color. The color of the $ i $ -th vertex is an integer $ c_{i} $ . Let's consider all vertices of the graph, that are painted some color $ k $ . Let's denote a set of such as $ V(k) $ . Let's denote the value of the neighbouring color diversity for color $ k $ as the cardinality of the set $ Q(k)={c_{u} : c_{u}≠k $ and there is vertex $ v $ belonging to set $ V(k) $ such that nodes $ v $ and $ u $ are connected by an edge of the graph $ } $ . Your task is to find such color $ k $ , which makes the cardinality of set $ Q(k) $ maximum. In other words, you want to find the color that has the most diverse neighbours. Please note, that you want to find such color $ k $ , that the graph has at least one vertex with such color.

输入输出格式

输入格式


The first line contains two space-separated integers $ n,m $ $ (1<=n,m<=10^{5}) $ — the number of vertices end edges of the graph, correspondingly. The second line contains a sequence of integers $ c_{1},c_{2},...,c_{n} $ $ (1<=c_{i}<=10^{5}) $ — the colors of the graph vertices. The numbers on the line are separated by spaces. Next $ m $ lines contain the description of the edges: the $ i $ -th line contains two space-separated integers $ a_{i},b_{i} $ $ (1<=a_{i},b_{i}<=n; a_{i}≠b_{i}) $ — the numbers of the vertices, connected by the $ i $ -th edge. It is guaranteed that the given graph has no self-loops or multiple edges.

输出格式


Print the number of the color which has the set of neighbours with the maximum cardinality. It there are multiple optimal colors, print the color with the minimum number. Please note, that you want to find such color, that the graph has at least one vertex with such color.

输入输出样例

输入样例 #1

6 6
1 1 2 3 5 8
1 2
3 2
1 4
4 3
4 5
4 6

输出样例 #1

3

输入样例 #2

5 6
4 2 5 2 4
1 2
2 3
3 1
5 3
5 4
3 4

输出样例 #2

2

Input

题意翻译

有N个点,每个顶点对应一种颜色,可以相同。给出连接这些顶点的M边,定义Q(k)是所有颜色为k的所有顶点相连的不同的颜色的总数量(不包含k),求使得Q(k)最大时的k的值,如果有多个k 值满足,输出最小的k值 感谢@Ricardo_Ni 提供的翻译

加入题单

算法标签: