【链接】 我是链接,点我呀:)

【题意】

让你找到所有和x颜色的点中,和该颜色的点颜色不同的相邻的点的个数(重复颜色算一次)
求出哪种颜色的所要求的点的数量最多.

【题解】

对于每一条边只会被查到两次。
所以按照题意暴力枚举的时间复杂度就是O(n+m)级别的
至于查重 只要对找过的点打个标记就很好处理的

【代码】

import java.io.*;
import java.util.*; public class Main { static InputReader in;
static PrintWriter out; public static void main(String[] args) throws IOException{
//InputStream ins = new FileInputStream("E:\\rush.txt");
InputStream ins = System.in;
in = new InputReader(ins);
out = new PrintWriter(System.out);
//code start from here
new Task().solve(in, out);
out.close();
} static int N = (int)1e5;
static class Task{ int n,m;
int c[] = new int[N+10];
ArrayList<Integer> g[] = new ArrayList[N+10];
ArrayList<Integer> col[] = new ArrayList[N+10];
int mark[] = new int[N+10]; public void solve(InputReader in,PrintWriter out) {
for (int i = 1;i <= N;i++) g[i] = new ArrayList<Integer>();
for (int i = 1;i <= N;i++) col[i] = new ArrayList<Integer>();
n = in.nextInt();m = in.nextInt();
for (int i = 1;i <= n;i++) {
c[i] = in.nextInt();
col[c[i]].add(i);
}
for (int i = 1;i <= m;i++) {
int x,y;
x = in.nextInt();y = in.nextInt();
g[x].add(y);g[y].add(x);
}
int ans = -1,idx = 0;
for (int i = 1;i <= N;i++)
if (!col[i].isEmpty()) {
int cnt = 0;
for (int J = 0;J < (int)col[i].size();J++) {
int x = col[i].get(J);
int len = g[x].size();
for (int j = 0;j < len;j++) {
int y = g[x].get(j);
if (c[y]!=c[x]) {
if (mark[c[y]]!=i) {
cnt++;
mark[c[y]] = i;
}
}
}
}
if (cnt>ans) {
ans = cnt;
idx = i;
}
}
out.println(idx);
}
} static class InputReader{
public BufferedReader br;
public StringTokenizer tokenizer; public InputReader(InputStream ins) {
br = new BufferedReader(new InputStreamReader(ins));
tokenizer = null;
} public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.readLine());
}catch(IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
} public int nextInt() {
return Integer.parseInt(next());
}
}
}

【Codeforces 246D】Colorful Graph的更多相关文章

  1. 【Codeforces 404C】Restore Graph

    [链接] 我是链接,点我呀:) [题意] 每个节点的度数不超过k 让你重构一个图 使得这个图满足 从某个点开始到其他点的最短路满足输入的要求 [题解] 把点按照dep的值分类 显然只能由dep到dep ...

  2. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  3. 【codeforces 755E】PolandBall and White-Red graph

    [题目链接]:http://codeforces.com/contest/755/problem/E [题意] 给你n个节点; 让你在这些点之间接若干条边;构成原图(要求n个节点都联通) 然后分别求出 ...

  4. 【codeforces 716D】Complete The Graph

    [题目链接]:http://codeforces.com/problemset/problem/716/D [题意] 给你一张图; 这张图上有一些边的权值未知; 让你确定这些权值(改成一个正整数) 使 ...

  5. 【34.57%】【codeforces 557D】Vitaly and Cycle

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. 【27.91%】【codeforces 734E】Anton and Tree

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. 【30.36%】【codeforces 740D】Alyona and a tree

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. 【codeforces 755C】PolandBall and Forest

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  9. 【13.91%】【codeforces 593D】Happy Tree Party

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

随机推荐

  1. JSP共享范围

    概念:对象的声明周期和可访问性称为作用域(scope). 注:有时候内置对象的作用域一旦设置就不能修改,其他对象(如JavaBean)可以设置他的作用域 作用域类型: Page:页面域(对象只对于它所 ...

  2. Net 发布网站中遇到的几点问题

    1.windows 身份验证设置 打开IIS==>=>找到网站==> 身份验证==>打开功能==>启用windows身份验证 网站设置: 博客参考: http://blo ...

  3. hbase本地调试环境搭建

    1,前言 想要深入的了解hbase,看hbase源码是必须的.以下描述了搭建hbase本地调试环境的经历 2,安装步骤 2.1,启动hbase 1,安装java和IDE IntelliJ,下载源码等. ...

  4. 构建一个.net的干货类库,以便于快速的开发 - 前言

    前言: 工作已经快两年了,项目也做过不少,不知道大家有没有一个习惯,就是把在做项目过程中那些好的方法记录下来.我觉得这个习惯在开发的过程中还是很有用的,举个例子,我之前做过一个支付宝的支付功能,然后把 ...

  5. 创建对象——单例(Singleton)模式

      单例(Singleton)模式:   保证一个类在系统里只能有一个对象被实例化.   如:缓存池.数据库连接池.线程池.一些应用服务实例等.   难点:在多线程环境中,保证实例的唯一性.     ...

  6. shim和polyfill有什么区别

    在JavaScript的世界里,有两个词经常被提到,shim和polyfill.它们指的都是什么,又有什么区别? 一个shim是一个库,它将一个新的API引入到一个旧的环境中,而且仅靠旧环境中已有的手 ...

  7. 【PostgreSQL-9.6.3】物化视图

    PostgreSQL 9.3 以后出现了物化视图.物化视图是由实实在在的数据组成,这是和一般视图的根本区别. 1. 物化视图创建语法如下: --创建语法 CREATE MATERIALIZED VIE ...

  8. Maven之pom.xml详释

    什么是pom? POM(Project Object Model):全称项目对象模型,它是Maven项目中的文件,使用XML表示,名称叫做pom.xml.在Maven项目中,必须包含pom.xml文件 ...

  9. 出现For input string: "" 错误

    然后是因为后台生成的是一个数组,前台取的是一个对象,所以会产生这个错误 前后台交互时 mv.addObject("vo1",fhList.get(0));}将数组改成fhList. ...

  10. layer弹出层无法关闭问题

    parent.layer.closeAll();如果关闭指定弹出层,获取对应弹出层的索引,进行关闭