日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【CodeForces - 246D】Colorful Graph (暴力,图,存边,STL)

發布時間:2023/12/10 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【CodeForces - 246D】Colorful Graph (暴力,图,存边,STL) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

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?≤?n;?ai?≠?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 6 1 1 2 3 5 8 1 2 3 2 1 4 4 3 4 5 4 6

Output

3

Input

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

Output

2

題目大意:

? ?定義點集V(k)和基數Q(k),分別代表涂有顏色k的點集;顏色為k的所有頂點相連的邊的顏色共有多少種(就是 不以頂點為單位,而以顏色為k? 為單位)。

? ?輸入n和m,代表n個點m條邊,然后輸入n個點的顏色,然后輸入m條邊。(但是一直不知道Output里面那個Node提示有啥用、、)

解題報告:

? ? set爆搞。

AC代碼:

#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define ll long long #define pb push_back #define pm make_pair #define fi first #define se second using namespace std; const int MAX = 2e5 + 5; int n,m; int col[MAX]; set<int> ss[MAX]; int main() {cin>>n>>m;for(int i = 1; i<=n; i++) {scanf("%d",col+i);}int u,v;for(int i = 1; i<=m; i++) {scanf("%d%d",&u,&v);if(col[u] != col[v]) {ss[col[u]].insert(col[v]);ss[col[v]].insert(col[u]);}}int ans = 0,ansi=0x3f3f3f3f;for(int i = 1; i<=n; i++) {if(ss[col[i]].size() > ans) {ansi = col[i];ans = ss[col[i]].size(); }else if(ss[col[i]].size() == ans) {ansi = min(ansi,col[i]);ans = ss[col[i]].size();} // if(ss[col[i]].size()>= ans) { // ansi = min(ansi,col[i]); // ans = ss[col[i]].size(); // }}printf("%d\n",ansi);return 0 ;}

總結:

? ?注意一下最后判斷的時候別寫成注釋那樣的,,,,應該跟最短路條數那種判斷一樣。。。反正注意一下就好了。。

總結

以上是生活随笔為你收集整理的【CodeForces - 246D】Colorful Graph (暴力,图,存边,STL)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。