找出连通块,然后找出颜色最大的,用总数减去

#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的更多相关文章

  1. 【36.11%】【codeforces 725C】Hidden Word

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

  2. CodeForces Canada Cup 2016【A,B,C,D】

    CodeForces 725A: 思路就是如果"最左"不是'>'这个了,那么这个右边的一定不可能到达左边了: 同理最右: CodeForces 725B: 有两个空姐,一个从 ...

  3. Intel CPU Microarchitecture

    http://en.wikipedia.org/wiki/Intel_Tick_Tock Atom Roadmap[16]   Fabrication process Microarchitectur ...

  4. Intel processor brand names-Xeon,Core,Pentium,Celeron----Celeron

    http://en.wikipedia.org/wiki/Celeron Celeron From Wikipedia, the free encyclopedia     Celeron Produ ...

随机推荐

  1. easyUI的dateBox控制时间格式

    <input type='text' name='yearQuery' class='easyui-datebox ' data-options="formatter:myformat ...

  2. [No000062]读书八字诀:怎样将书读得通透?

    从吃透到通透 有种说法,吃透一本书,才算好好读过.然而比吃透境界更高,是通透.吃透仅限于书中内容,通透则是将书中内容与正反上下.古今中外背景知识相互关联. 当你做到读书通透,收获将远远大于手头那一本书 ...

  3. javascript删除元素节点

    1.删除元素父节点 function removeElement(_element){ var _parentElement = _element.parentNode; if(_parentElem ...

  4. Android的4种文件类型Java,class,dex,apk

    Java文件-----应用程序源文件 Android本身相当一部分都是用java编写而成(基本上架构图里头蓝色的部份都是用Java开发的),android的应用必须使用java来开发 Class文件- ...

  5. 借助91助手,将ibook中的pdf文件拷贝至其它的pdf阅读器中(ios设备无需越狱)

    有时候在使用ios自带的ibook阅读pdf文件的时候,会发现ibook有些功能并不是那么方便.最近我就遇到了一例,我想在ibook中放一本比较大的pdf书,页数有几百吧,pdf文件本身每一章节都是有 ...

  6. python-day02数据类型-字符串和列表的操作

    while循环: while True: 条件语句....... 关于break和continue,break:跳出当前的循环                               contnu ...

  7. http协议(九)响应首部字段

    响应首部字段: 服务器向客户端返回响应报文中所使用的字段,用于补充的附加信息.服务器信息.以及对客户端的附加要求等 1.Accept-Ranges 告知客户端服务器能否处理范围请求,以指定获取服务器的 ...

  8. gitlab两种连接方式:ssh和http配置介绍

    gitlab环境部署好后,创建project工程,在本地或远程下载gitlab代码,有两种方式:ssh和http (1)ssh方式:这是一种相对安全的方式 这要求将本地的公钥上传到gitlab中,如下 ...

  9. Router的创建者——RouteBuilder

    Router的创建者--RouteBuilder 在<注册URL模式与HttpHandler的映射关系>演示的实例中,我们总是利用一个RouteBuilder对象来为RouterMiddl ...

  10. nginx架构

    nginx平台初探(100%)