Codeforces 246D Colorful Graph【STL瞎暴力】

来源:互联网 发布:宁波最新房价走势知乎 编辑:程序博客网 时间:2024/05/22 14:21

D. Colorful Graph
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 ci.

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) = {cu :  cu ≠ 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.

Input

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 c1, c2, ..., cn (1 ≤ ci ≤ 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 ai, bi (1 ≤ ai, bi ≤ nai ≠ bi) — 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.

Output

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.

Examples
input
6 61 1 2 3 5 81 23 21 44 34 54 6
output
3
input
5 64 2 5 2 41 22 33 15 35 43 4
output
2



/*    题意:有一个无向简单图,每个定点有一个颜色编号,求相邻颜色种类数最多的颜色的编号是多少          如果有多个满足条件的输出最小编号*/#include<cstdio>#include<iostream>#include<queue>#include<algorithm>#include<set>#include<vector>using namespace std;const int maxn = 1e5+5;vector<int>G[maxn];int c[maxn];vector<int>clo[maxn];set<int>cnt[maxn];int main(){    int n,m;    cin>>n>>m;    for(int i=1;i<=n;i++){        scanf("%d",&c[i]);        clo[c[i]].push_back(i);    }    for(int i=1;i<=m;i++){        int u,v;        scanf("%d%d",&u,&v);        G[u].push_back(v);        G[v].push_back(u);    }    int ans=0;    for(int i=1;i<maxn;i++){        int len=clo[i].size();        for(int j=0;j<len;j++){            int u=clo[i][j];            int len1=G[u].size();            for(int k=0;k<len1;k++){                int v=G[u][k];                cnt[i].insert(c[v]);            }            cnt[i].insert(c[u]);        }        ans=max(ans,(int)cnt[i].size()-1);    }    for(int i=1;i<maxn;i++){        if(cnt[i].size()-1==ans){            printf("%d\n",i);            break;        }    }    return 0;}


0 0