Codeforces--246D--Colorful Graph(STL set)
来源:互联网 发布:淘宝自动发货没收到 编辑:程序博客网 时间:2024/06/01 07:52
Description
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.
Sample Input
6 61 1 2 3 5 81 23 21 44 34 54 6
3
5 64 2 5 2 41 22 33 15 35 43 4
2
n个点,每个点都有对应颜色,然后有m条无向边然后输出一个点的颜色,这个点附近不同的颜色应该是最多的,并且这个点的下标应该最小
#include<cstdio>#include<set>#include<cstring>#include<algorithm>using namespace std;int vis[1000005],num[1000005];set<int>s[1000005];int main(){int n,m;while(scanf("%d%d",&n,&m)!=EOF){memset(vis,0,sizeof(vis));for(int i=0;i<1000005;i++)s[i].clear();int x;for(int i=1;i<=n;i++){scanf("%d",&x);num[i]=x;vis[x]=1;}int u,v;for(int i=0;i<m;i++){scanf("%d%d",&u,&v);if(num[u]!=num[v]){s[num[u]].insert(num[v]);s[num[v]].insert(num[u]);}}int ans=0,temp;for(int i=1;i<=1000005;i++){if(vis[i]&&((int)s[i].size())>ans){ans=s[i].size();temp=i;}}if(ans==0){for(int i=0;i<1000005;i++){if(vis[i]){temp=i;break;}}}printf("%d\n",temp);}return 0;}
- Codeforces--246D--Colorful Graph(STL set)
- Codeforces--246D--Colorful Graph(STL set)(好题)
- 【codeforces 246D Colorful Graph 】+ set
- codeforces 246 D. Colorful Graph (set)
- CodeForces 246D. Colorful Graph【STL】
- Codeforces 246D Colorful Graph【STL瞎暴力】
- codeforces 246D. Colorful Graph
- codeforces 246/D Colorful Graph
- Codeforces 246D. Colorful Graph
- Codeforces 246D Colorful Graph 【DFS】
- Codeforces Round #286 (Div. 1) D. Mr. Kitayuta's Colorful Graph (并查集 STL)
- Codeforces Round #286 (Div. 1) D. Mr. Kitayuta's Colorful Graph 高维并查集,STL连招
- Colorful Graph CodeForces
- codeforces 675D (STL set)
- CodeForces-505B-Mr. Kitayuta's Colorful Graph(弗洛伊德)
- Codeforces 506D:Mr. Kitayuta's Colorful Graph 并查集
- Codeforces Round #286 div.1 D 506D D. Mr. Kitayuta's Colorful Graph【并查集】
- CODEFORCES 264D Colorful Stones
- Adam学习13之Fasta/Fastq/SAM/BAM文件格式数据读取
- Oculus调试工具
- Angular-Touch库使用
- [Python]List,Tuple,循环
- Java对象死亡标记的过程
- Codeforces--246D--Colorful Graph(STL set)
- U-Boot 下载地址
- matlab机器人工具箱的安装和使用
- CodeForces - 246A Buggy Sorting (模拟)水
- Java 作业2 Java API
- [转载]使用Fragment完成Tab选项卡-Android Fragment应用实战
- DP 动态规划 Problem F 1006 数塔问题
- 【一天一道LeetCode】#38. Count and Say
- leetcode——105——Construct Binary Tree from Preorder and Inorder Traversal