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 ...
随机推荐
- 第18章 图元文件_18.2 增强型图元文件(emf)(2)
18.2.7 增强型图元文件的查看和打印程序 (1)传递EMF到剪贴板,剪贴板类型应为:CF_ENHMETAFILE (2)CopyEnhMetaFile用于复制图元文件 (3)剪贴板中的图元文件会自 ...
- ExecutorType 的类型
- 用FLASH,安智和IOS打电话方法
打电话?你直接urlrequest不就打出去了吗普通网页http://xxx电话tel://xxx要啥ane
- 嵌入式Linux驱动学习之路(九)Linux系统调用、驱动程序框架
应用程序通过open read write close 等函数来操作计算机硬件.类似是一个接口. 当应用程序调用这些接口程序时,计算机是如何进入内核的呢?这是经过了系统调用. 实际上当调用接口函数 ...
- java 27 - 3 反射之 通过反射获取构造方法并使用
类 Constructor<T>:提供关于类的单个构造方法的信息以及对它的访问权限. 通过反射的方法获取构造方法并使用 ps:先忽略泛型 A.1:获取构造方法的数组: public Co ...
- bzoj4034: [HAOI2015]T2
4034: [HAOI2015]T2 Time Limit: 10 Sec Memory Limit: 256 MB Submit: 2684 Solved: 843 Description 有一 ...
- Java Web开发Tomcat中三种部署项目的方法
第一种方法:在tomcat中的conf目录中,在server.xml中的,<host/>节点中添加: <Context path="/hello" docBase ...
- [转]一篇很全面的freemarker教程
copy自http://demojava.iteye.com/blog/800204 以下内容全部是网上收集: FreeMarker的模板文件并不比HTML页面复杂多少,FreeMarker模板文件主 ...
- velocity模板引擎学习(2)-velocity tools 2.0
使用velocity后,原来的很多标签无法使用了,必须借助velocity tools来完成,目前velocity tools最新版本是2.0,下面是velocity tools的一些注意事项: 1. ...
- 利用performance属性查看网页性能
一般我们可以通过浏览器的调试工具-网络面板,或者代理工具查看网页加载过程中的各个阶段的耗时.而利用window.performance属性则可以获得更为精确的原始数据,以毫秒为单位,精确到微秒. pe ...