725C
找出连通块,然后找出颜色最大的,用总数减去
#include<iostream>
#include<map>
#include<cstring>
#include<vector>
#include<cstdio>
using namespace std;
vector<int>graph[200010];
int n,m,k,ans,temp,tot;
map<int,int>color;
int use[200010],a[200010],used[200010];
inline void dfs(int u)
{
used[u]=1;
tot++;
for(int i=0;i<graph[u].size();i++)
{
int v=graph[u][i];
if(!used[v]) color[a[v]]++;
if(color[a[v]]>temp) temp=color[a[v]];
if(!used[v]) dfs(v);
}
}
int main()
{
cin>>n>>m>>k;
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(int i=1;i<=m;i++)
{
int l,r;
scanf("%d%d",&l,&r);
use[l]=1;
use[r]=1;
graph[l].push_back(r);
graph[r].push_back(l);
}
for(int i=1;i<=n;i++)
{
if(!used[i]&&use[i])
{
tot=0;
temp=0;
color.clear();
color[a[i]]++;
dfs(i);
ans+=tot-temp;
}
}
cout<<ans<<endl;
return 0;
}
725C的更多相关文章
- 【36.11%】【codeforces 725C】Hidden Word
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- CodeForces Canada Cup 2016【A,B,C,D】
CodeForces 725A: 思路就是如果"最左"不是'>'这个了,那么这个右边的一定不可能到达左边了: 同理最右: CodeForces 725B: 有两个空姐,一个从 ...
- Intel CPU Microarchitecture
http://en.wikipedia.org/wiki/Intel_Tick_Tock Atom Roadmap[16] Fabrication process Microarchitectur ...
- Intel processor brand names-Xeon,Core,Pentium,Celeron----Celeron
http://en.wikipedia.org/wiki/Celeron Celeron From Wikipedia, the free encyclopedia Celeron Produ ...
随机推荐
- 异常总结<经典例题>
public class Test1 { public static void main(String[] args) { try { add(1); System.out.println(" ...
- Unity 5 WebGL vs Web Player
起原 Unity5.3中看到Web Player未来将到被取消,根据Unity官方blog中称Unity5.4中将会移除web player. 本文从我知道的知识比较一下webPlayer和WebGL ...
- 搞netty
开始搞netty了 查了下资料 在使用NIO 的时候,最好不要配置 SO_LINGER,假设设置了该參数,在 close的时候如缓冲区有数据待写出,会抛出 IOException. // 在netty ...
- C# String.split()用法小结。String.Split 方法 (String[], StringSplitOptions)
split()首先是一个分隔符,它会把字符串按照split(' 字符')里的字符把字符串分割成数组,然后存给一个数组对象. 输出数组对象经常使用foreach或者for循环. 第一种方法 string ...
- redis 学习笔记(3)-master/slave(主/从模式)
类似mysql的master-slave模式一样,redis的master-slave可以提升系统的可用性,master节点写入cache后,会自动同步到slave上. 环境: master node ...
- JavaScript:立即执行的函数表达式
先要理解清楚几个概念: 以下转自:http://www.cnblogs.com/TomXu/archive/2011/12/31/2289423.html 问题的核心 当你声明类似functio ...
- 如何在 ie6 中使用 "localStorage"
好吧,我只是个标题党,ie6 下根本无法使用跟 h5 沾边的 localStorage.今天要向大家介绍的是 ie 特有的 userData 的存储方式,并且对它进行封装,使得不支持 localSto ...
- nios II--实验4——按键中断软件部分
软件开发 首先,在硬件工程文件夹里面新建一个software的文件夹用于放置软件部分:打开toolsàNios II 11.0 Software Build Tools for Eclipse,需要进 ...
- [bzoj 3531][SDOI2014]旅行(树链剖分+动态开点线段树)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=3531 分析: 对于每个颜色(颜色<=10^5)都建立一颗线段树 什么!那么不是M ...
- Matlab中函数定义方法
Matlab自定义函数的六种方法 n1.函数文件+调用函数(命令)文件:需单独定义一个自定义函数的M文件: n2.函数文件+子函数:定义一个具有多个自定义函数的M文件: n3.Inline:无需M文件 ...