CF246D.Colorful Graph
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
你有一个包含 n 个顶点和 m 条边的无向图。我们将图中的顶点编号为从 1 到 n 的整数。图中每个顶点均有一种颜色,第 i 个顶点的颜色为整数 ci。
考虑图中所有颜色为 k 的顶点,记该顶点集合为 V(k)。我们定义颜色 k 的邻接颜色多样性(neighbouring color diversity)为集合
Q(k)={cu:cu=k 且存在顶点 v∈V(k),使得 v 与 u 在图中由一条边相连}
的基数(即元素个数)。
你的任务是找出使得集合 Q(k) 的基数最大的颜色 k。换言之,你要找出具有最多样化邻接颜色的那个颜色。请注意:你所寻找的颜色 k 必须满足图中至少存在一个顶点具有该颜色。
输入格式
The first line contains two space-separated integers n, m (1 ≤ n, m ≤ 105) — 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 ≤ 105) — 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.
第一行包含两个以空格分隔的整数 n 和 m(1≤n,m≤105),分别表示图的顶点数和边数。
第二行包含一个整数序列 c1,c2,…,cn(1≤ci≤105),表示图中各顶点的颜色。该行数字以空格分隔。
接下来 m 行描述图的边:第 i 行包含两个以空格分隔的整数 ai,bi(1≤ai,bi≤n;ai=bi),表示第 i 条边所连接的两个顶点的编号。
保证所给图不含自环或重边。
输出格式
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
输入解题思路,AI测评打分。不知道怎么写?