题干:

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 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)相关推荐

  1. Graph Representation 图神经网络

    Graph Representation 图神经网络 图表示学习(representation learning)--图神经网络框架,主要涉及PyG.DGL.Euler.NeuGraph和AliGra ...

  2. golang通过itemid获取zabbix graph监控图

    2019独角兽企业重金招聘Python工程师标准>>> #简述 本文将使用golang和第三方http client 库gorequest编写.如需要只使用golang 标准库可以参 ...

  3. graph 关系图 设置

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  4. 505B. Mr. Kitayuta‘s Colorful Graph

    B. Mr. Kitayuta's Colorful Graph:题目 一开始就像到了DFS,并查集也不难想到. 弗洛伊德算法倒是不容易想到,平时不这么用..... #include <bits ...

  5. 当前数据库普遍使用wait-for graph等待图来进行死锁检测

    当前数据库普遍使用wait-for graph等待图来进行死锁检测 较超时机制,这是一种更主动的死锁检测方式,innodb引擎也采用wait-for graph SQL Server也使用wait-f ...

  6. 向图共生|金科览智加入创邻科技“Graph+X”图智能生态合作体系

    "Graph+X"图智能生态合作计划是创邻科技围绕核心产品Galaxybase图平台,面向解决方案商.系统集成商.服务伙伴推出的一项生态合作计划,旨在于构建持续发展.合作共赢的图技 ...

  7. Graph(图)干货归纳+用法示例

    11.Graph图 一.Graph(图)简介 1.图的特点: 2.使用场景: 3.如何实现(邻接表.邻接矩阵): 二.DFS(深度优先搜索) 1.DFS步骤 2.DFS示例 三.BFS(广度优先搜索) ...

  8. echarts graph关系图自定义线条label颜色

    echarts graph关系图自定义线条label颜色 一.按条件匹配自定义颜色 echarts 关系图自定义线条label颜色 自定义label颜色:通过配置edgeLabel中的rich和for ...

  9. Codeforces Round #635 (Div. 2) D. Xenia and Colorful Gems 暴力 + 二分

    传送门 文章目录 题意: 思路: 题意: 给你三个数组a,b,ca,b,ca,b,c,让你从每个数组中选择一个数x,y,zx,y,zx,y,z,使得(x−y)2+(x−z)2+(y−z)2(x-y)^ ...

最新文章

  1. xshell 6和xftp 6的下载和使用
  2. 【转载保存】获取页面编码
  3. xrdpdf卡片在哪可下载_暑假学习英语字母,就是这样简单(附可打印字母卡下载)...
  4. iOS : 静态库(.framework)合并
  5. html为什么div移动不了,如何使用Jquery将html从一个div移动到另一个div而不会破坏javascript...
  6. LLVM和clang
  7. jax-ws开发的webservice集成到web项目中
  8. webpack的sourcemap
  9. 用C#获取当前的路径
  10. oj 26319 最大子序和
  11. 【HackerRank】Cut the tree
  12. 【框架----Dubbo】基于开源Dubbo分布式RPC服务框架的部署整合
  13. C 语言编程计算年龄,C#实现计算年龄的简单方法汇总
  14. Robust PCA——Inexect ALM
  15. navigate实现页面跳转及传参
  16. MySQL按日期依次统计
  17. 计算机网络系统不可用,网络连接不可用,小编教你电脑网络连接不可用怎么办...
  18. 树莓派官网VNC配置
  19. 数学故事在小学数学课堂教学中的应用研究
  20. 5G移动通信系统设计与标准详解 个人整理(PDF和Word)

热门文章

  1. 154. Find Minimum in Rotated Sorted Array II
  2. Linux启动过程以及初始化
  3. 回溯——伯努利装错信封问题
  4. cesium添加填充_Cesium中级教程1 - 空间数据可视化(一)
  5. linux uuid错误,Linux 错误:fatal error: uuid/uuid.h: No such file or directory
  6. android 设置线程优先级
  7. php编译称opcode文件,PHP源码保护和性能加速
  8. linux远程虚拟桌面,2020-07-23 Linux 远程连接虚拟桌面
  9. debian执行php网页,如何在Debian上安装和使用PHP Composer
  10. ssh密钥代理转发(ssh agent forwarding)