CodeForces 246D. Colorful Graph【STL】
来源:互联网 发布:淘宝网1.4 餐桌 编辑:程序博客网 时间:2024/06/05 16:51
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 integerci.
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 ≠ kand 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.
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.
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
题意:
题目说,每个顶点对应一种颜色,可以相同。给出连接这些顶点的若干条边,定义Q(k)是所有颜色为k的所有顶点相连的不同的颜色的总数量(不包含k),求使得Q(k)最大时的k的值,如果有多个k 值满足,输出最小的k值.....
题解:
题目看了好久才看明白....英语水平确实很伤.....
需要用map和set ,因为数据给的比较小,直接暴力进行,否则则需要进行离散化对应(不会...)...
/*http://blog.csdn.net/liuke19950717*/#include<cstdio>#include<cstring>#include<map>#include<set>using namespace std;const int maxn=100005;set<int> vis[maxn];void init(){for(int i=0;i<maxn;++i){vis[i].clear();}}int main(){int n,m;while(~scanf("%d%d",&n,&m)){init();map<int,int> map;for(int i=1;i<=n;++i){int a;scanf("%d",&a);map[i]=a;}for(int i=0;i<m;++i){int a,b;scanf("%d%d",&a,&b);if(map[a]!=map[b])//和自身相等的颜色不算{vis[map[a]].insert(map[b]);vis[map[b]].insert(map[a]);}}int ans=map[1];for(int i=1;i<=n;++i){if(vis[ans].size()<vis[map[i]].size()||vis[ans].size()==vis[map[i]].size()&&ans>map[i])//判断条件{ans=map[i];}}printf("%d\n",ans);}return 0;}
- CodeForces 246D. Colorful Graph【STL】
- Codeforces--246D--Colorful Graph(STL set)
- Codeforces 246D Colorful Graph【STL瞎暴力】
- codeforces 246D. Colorful Graph
- codeforces 246/D Colorful Graph
- Codeforces 246D. Colorful Graph
- Codeforces 246D Colorful Graph 【DFS】
- 【codeforces 246D Colorful Graph 】+ set
- codeforces 246 D. Colorful Graph (set)
- Codeforces--246D--Colorful Graph(STL set)(好题)
- 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 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
- mac下配置Qt for Android编译环境
- Build Your First Mobile App With Ionic 2 & Angular 2 - Part 7
- printf输出格式总结
- Airbnb 分享经济步步紧逼:传统酒店老板要和出租车司机同病相怜?
- SQL命令和常用语句大全
- CodeForces 246D. Colorful Graph【STL】
- 正则使用的相关实例(判断邮箱,电话号码等)
- 自定义viewGroup
- 阶乘与 pi 的关系 —— 斯特林公式(Stirling formula)
- 运行加载数据
- webView加载的图片添加点击事件
- Ubuntu14.04安装cscope
- 数据科学与机器学习管道中预处理的重要性(一):中心化、缩放和K近邻
- 关于动态壁纸商城的撸码