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

【题意】

让你找到所有和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. 2-4 Vue中的属性绑定和双向数据绑定

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. bzoj 1709: [Usaco2007 Oct]Super Paintball超级弹珠【枚举】

    k是1e5范围的,吗? 注意到n只有100,这意味着k去重之后之后n^2,也就是1e4! 然后就可以愉快的n^4枚举了,枚举每个格子,再枚举每个敌人,如果当前格子射不到敌人则退出,否则满足所有敌人则a ...

  3. bzoj 1629: [Usaco2007 Demo]Cow Acrobats【贪心+排序】

    仿佛学到了贪心的新姿势-- 考虑相邻两头牛,交换它们对其他牛不产生影响,所以如果交换这两头牛能使这两头牛之间的最大值变小,则交换 #include<iostream> #include&l ...

  4. [App Store Connect帮助]四、添加 App 图标、App 预览和屏幕快照(3)上传 App 预览和屏幕快照

    请上传至多三个 App 预览和至多十张屏幕快照.如果您的 App 在不同设备尺寸和本地化内容间都相同,仅提供所要求的最高分辨率的屏幕快照即可. 对于 iPhone,必须提供用于 5.5 英寸设备(iP ...

  5. RabbitMQ的一些基本操作

    $ sudo chkconfig rabbitmq-server on # 添加开机启动RabbitMQ服务 $ sudo /sbin/service rabbitmq-server start # ...

  6. 235 Lowest Common Ancestor of a Binary Search Tree 二叉搜索树的最近公共祖先

    给定一棵二叉搜索树, 找到该树中两个指定节点的最近公共祖先. 详见:https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-s ...

  7. Java 8 (11) 新的日期和时间API

    在Java 1.0中,对日期和时间的支持只能依赖java.util.Date类.这个类只能以毫秒的精度表示时间.这个类还有很多糟糕的问题,比如年份的起始选择是1900年,月份的起始从0开始.这意味着你 ...

  8. 如何向expect脚本里面传递参数

    如何向expect脚本里面传递参数   比如下面脚本用来做ssh无密码登陆,自动输入确认yes和密码信息,用户名,密码,hostname通过参数来传递   ssh.exp   Python代码   # ...

  9. NodeJS —— 自定义流的实现

    概述 常见的自定义流有四种,Readable(可读流).Writable(可写流).Duplex(双工流)和 Transform(转换流),常见的自定义流应用有 HTTP 请求.响应,crypto 加 ...

  10. python学习笔记- 补遗

    1.extend 和 append区别 extend 和 append区别 #extend接受list参数,添加每个元素至原list尾端 >>> l=[1,2,3] >> ...