codeforces 246 D. Colorful Graph (set)
来源:互联网 发布:淘宝怎么做免费推广 编辑:程序博客网 时间:2024/06/05 14:08
D. Colorful Graph
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 colork. Let's denote a set of such as V(k). Let's denote the value of theneighbouring 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 setQ(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.
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 integersc1, 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.
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.
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条边,问相邻的颜色最多的颜色号码是多少
code:
#include <iostream>#include<cstdio>#include<set>#include<cstring>using namespace std;set<int>s[100010];int co[100010];bool vis[100010];int main(){ int n,m,x,y; scanf("%d%d",&n,&m); memset(vis,0,sizeof(vis)); for(int i=1;i<=n;i++) { s[i].clear(); scanf("%d",&co[i]); vis[co[i]]=1; } for(int i=1;i<=m;i++) { scanf("%d%d",&x,&y); { if(co[x]!=co[y]) { s[co[x]].insert(co[y]); s[co[y]].insert(co[x]); } } } int maxn=-1,ans; for(int i=1;i<100001;i++) { if(vis[i]&&maxn<(int)s[i].size()) { maxn=(int)s[i].size(); ans=i; } } printf("%d\n",ans); return 0;}
- 【codeforces 246D Colorful Graph 】+ set
- codeforces 246 D. Colorful Graph (set)
- Codeforces--246D--Colorful Graph(STL set)
- codeforces 246D. Colorful Graph
- codeforces 246/D Colorful Graph
- Codeforces 246D. Colorful Graph
- Codeforces 246D Colorful Graph 【DFS】
- CodeForces 246D. Colorful Graph【STL】
- Codeforces--246D--Colorful Graph(STL set)(好题)
- Codeforces 246D Colorful Graph【STL瞎暴力】
- Colorful Graph CodeForces
- Codeforces Round #286 (Div. 1) D. Mr. Kitayuta's Colorful Graph (并查集 STL)
- Codeforces 506D:Mr. Kitayuta's Colorful Graph 并查集
- Codeforces Round #286 div.1 D 506D D. Mr. Kitayuta's Colorful Graph【并查集】
- CODEFORCES 264D Colorful Stones
- 506D Mr. Kitayuta's Colorful Graph
- CodeForces 505BMr. Kitayuta's Colorful Graph
- Mr. Kitayuta's Colorful Graph CodeForces
- ConvertUtils转换器的使用
- 349. Intersection of Two Arrays
- QT中setLayout无效的问题
- 关于在win8.1(64位)上编写汇编教学
- Pheonix学习笔记 --- Blk Data Loading,Pheonix导如CSV文件
- codeforces 246 D. Colorful Graph (set)
- 领域驱动设计——浅析VO、DTO、DO、PO的概念、区别和用处
- RabbitMQ下的生产消费者模式与订阅发布模式
- 【AJAX进阶】——概念
- C语言itoa()函数和atoi()函数
- LinuxC测试题整理(一)
- C 线程与进程的区别与联系
- C++ int 型负数除法与求模运算
- Javascript的事件机制