Round 2 C
来源:互联网 发布:皇室战争数据 编辑:程序博客网 时间:2024/06/06 05:25
题目链接:
http://codeforces.com/problemset/problem/246/D
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
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
大意:
题目很长,一开始没看懂,位于补题之列。
一个无向图,每个点带一种颜色。
第一行输入顶点个数、边个数。
第二行依次表示每个顶点的颜色。
后 m 行表示边。
求
用
注意
int 和 unsigned int 不能比较,平时习惯不好,这次 -1 和 set<int>::size()就出错了
#include<bits/stdc++.h>#define mem(s,t) memset(s,t,sizeof(s))#define D(v) cout<<#v<<" "<<v<<endltypedef long long ll;using namespace std;//#define LOCALint n,m;const int MAXN =1e5+10;set<int> s[MAXN];int c[MAXN];int main(){#ifdef LOCAL freopen("in.txt","r",stdin); freopen("out.txt","w",stdout);#endif scanf("%d%d",&n,&m); mem(c,0); int l=MAXN+10,r=-1; for(int i=1;i<=n;i++){ scanf("%d",&c[i]); s[c[i]].insert(c[i]); if(l>c[i]) l=c[i]; if(r<c[i]) r=c[i]; } for(int i=1;i<=m;i++){ int x,y; scanf("%d%d",&x,&y); s[c[x]].insert(c[y]); s[c[y]].insert(c[x]); } int maxn=1,color=l; for(int i=l;i<=r;i++){ if(maxn<s[i].size()){ maxn=s[i].size(); color=i; } } cout<<color<<endl; return 0;}
- Round 2 C
- MemSQL Start[c]UP 2.0 - Round 2 - Online Round
- MemSQL Start[c]UP 2.0 - Round 2 - Online Round 题解
- Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] C 数学
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) C 模拟
- Codeforces Round #105 (Div. 2) C
- Codeforces Round 134 div 2 C题
- Codeforces Round #137 (Div. 2), problem: (C)
- Codeforces Round #153 (Div. 2) C题
- Codeforces Round #158 (Div. 2) C题
- Codeforces Round #162 (Div. 2) C
- Codeforces Round #166 (Div. 2) c. Secret
- Codeforces Round#170(Div 2)C
- Codeforces Round #173 (Div. 2) Problem C
- Round #172 (Div. 2) C. Rectangle Puzzle
- Codeforces Round #192 (Div. 2) C. Purification
- Codeforces Round #196 (Div. 2) C. Quiz
- Codeforces Round #197 (Div. 2) (C~E)
- 怎么转载CSDN博客
- Caffe tutorial 之 前向与反向传播
- 加密芯片——摘要算法特点与应用注意事项
- pyhon 打包命令 笔记
- ItemDecoration解析(一) getItemOffsets
- Round 2 C
- cocoapods找不到第三方库Unable to find a pod with name, author, summary, or descriptionmatching
- 水题 第四站 HDU 1003 Max Sum
- Python爬虫实战——签名软件设计(一)python POST模拟网页按钮点击
- 用 Doc2Vec 得到文档/段落/句子的向量表达
- ufldl学习笔记与编程作业:Logistic Regression(逻辑回归)
- 数字减影血管造影技术(DSA)
- 除了青春 我们一无所有
- java下的mysql数据库插入越插越慢的问题解决(百万数据量级别)