可能英语水平比较差,这个题我刚读起来是懵逼的。

C. Socks
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Arseniy is already grown-up and independent. His mother decided to leave him alone for m days and left on a vacation. She have prepared a lot of food, left some money and washed all Arseniy's clothes.

Ten minutes before her leave she realized that it would be also useful to prepare instruction of which particular clothes to wear on each of the days she will be absent. Arseniy's family is a bit weird so all the clothes is enumerated. For example, each of Arseniy's n socks is assigned a unique integer from 1 to n. Thus, the only thing his mother had to do was to write down two integers li and ri for each of the days — the indices of socks to wear on the day i (obviously, li stands for the left foot and ri for the right). Each sock is painted in one of kcolors.

When mother already left Arseniy noticed that according to instruction he would wear the socks of different colors on some days. Of course, that is a terrible mistake cause by a rush. Arseniy is a smart boy, and, by some magical coincidence, he posses k jars with the paint — one for each of k colors.

Arseniy wants to repaint some of the socks in such a way, that for each of m days he can follow the mother's instructions and wear the socks of the same color. As he is going to be very busy these days he will have no time to change the colors of any socks so he has to finalize the colors now.

The new computer game Bota-3 was just realised and Arseniy can't wait to play it. What is the minimum number of socks that need their color to be changed in order to make it possible to follow mother's instructions and wear the socks of the same color during each of m days.

Input

The first line of input contains three integers nm and k (2 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000, 1 ≤ k ≤ 200 000) — the number of socks, the number of days and the number of available colors respectively.

The second line contain n integers c1, c2, ..., cn (1 ≤ ci ≤ k) — current colors of Arseniy's socks.

Each of the following m lines contains two integers li and ri (1 ≤ li, ri ≤ nli ≠ ri) — indices of socks which Arseniy should wear during the i-th day.

Output

Print one integer — the minimum number of socks that should have their colors changed in order to be able to obey the instructions and not make people laugh from watching the socks of different colors.

Examples
input
3 2 3
1 2 3
1 2
2 3

output
2

input
3 2 2
1 1 2
1 2
2 1

output
0

Note

In the first sample, Arseniy can repaint the first and the third socks to the second color.

In the second sample, there is no need to change any colors.

题目大意:

题意:你有n双袜子,要穿m天,每个袜子都有一种颜色,你有k种颜料,每天给你指定两双袜子,你每天要穿这两双袜子出门,但是这两双袜子必须颜色一样,你可以对任意一个袜子进行染色,这样他们就一样了,问你:穿下这m天,最少要涂多少种颜色。

思路:你m天穿的袜子,如果有某几天穿的袜子是一样的,那么这几天的袜子都必须一样。这就是并查集了。。。用并查集把那一部分所有的袜子都变成一种颜色,最少的涂法就是用这个集合所有的袜子减去颜色最多的袜子就是最少的涂法,这样的集合可能在这m天有好几个,就分别统计每个集合的涂法。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
using namespace std;
int a[200005],col[200005],b[200005];
vector<int> ve[200005];
int find(int num){if(num==a[num])return num;else return a[num]=find(a[num]);
}
void insert(int l,int r){a[find(l)]=find(r);
}
int main(){int n,m,k;int i,j;int ans;set<int>st;scanf("%d %d %d",&n,&m,&k);int len;map<int,int>mp;int maxn;int l,r;for(i=1;i<=n;i++)a[i]=i;for(i=1;i<=n;i++){scanf("%d",&col[i]);}for(i=1;i<=m;i++){scanf("%d %d",&l,&r);insert(l,r);}len=0;for(i=1;i<=n;i++){if(find(i)==i){b[i]=len;len++;}}for(i=1;i<=n;i++){ve[b[find(i)]].push_back(col[i]);}ans=0;for(i=0;i<len;i++){maxn=0;for(j=0;j<ve[i].size();j++){mp[ve[i][j]]++;if(maxn<mp[ve[i][j]])maxn=mp[ve[i][j]];}ans+=ve[i].size()-maxn;mp.clear();}printf("%d\n",ans);return 0;
}

Codeforces Round #376 (Div. 2) C. Socks相关推荐

  1. Codeforces Round #376 (Div. 2) D. 80-th Level Archeology —— 差分法 + 线段扫描法

    题目链接:http://codeforces.com/contest/731/problem/D D. 80-th Level Archeology time limit per test 2 sec ...

  2. Codeforces Round #376 (Div. 2) B. Coupons and Discounts

    题目链接:http://codeforces.com/contest/731/problem/B #include<bits/stdc++.h> #define MX 200007 usi ...

  3. Codeforces Round #376 (Div. 2) D. 80-th Level Archeology

    原题网址:http://codeforces.com/contest/731/problem/D 对于相邻的两行,我们可以求出合法的答案区间,然后对所有的区间取一下区间并.因为只有最后一次询问,所以对 ...

  4. Codeforces Round #376 (Div. 2) D. 80-th Level Archeology(乱搞)

    题目链接: codeforces731d 题意: 给你n个字符串,每个字符串的元素x取值范围在[1,c],问你能否将所有的x同时进行若干次加1(如果x==c,x变成1)使得字符串是按字典序从小到大排序 ...

  5. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  6. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

  7. 构造 Codeforces Round #302 (Div. 2) B Sea and Islands

    题目传送门 1 /* 2 题意:在n^n的海洋里是否有k块陆地 3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 4 输出完k个L后,之后全部输出S:) 5 5 10 的例子可以 ...

  8. Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解 比赛链接:h ...

  9. Codeforces Round #712 Div.2(A ~ F) 超高质量题解(每日训练 Day.15 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #712 Div.2(A ~ F) 题解 比赛链接:https:// ...

最新文章

  1. windows笔记-内存映射文件
  2. SyncStudy Poster
  3. port-forward使用示例:kubectl port-forward deployment/kubernetes-dashboard -n kubernetes-dashboard :9090
  4. MFC COMBO-BOX最详细教程
  5. Node.js ES6模块化
  6. int a[5]={1,2,3,4,5}; int *p=(int*)(a+1); printf(%d,*(p-1)); 答案为什么是5?
  7. “搞机器学习没前途”
  8. 悟透delphi 第十一章 面向对象数据库基础
  9. YAML 有漏洞被弃用?网友:YAML 不背锅!
  10. cookie和session机制之间的区别与联系
  11. C语言 运算符与表达式
  12. 做了三年开发后,我选择回家创业
  13. 第二版 手把手教你如何建立自己的Linux系统
  14. 集合添加元素python_集 - 百度文库
  15. win10系统文件拖拽卡顿_如何解决Win10鼠标拖动窗口有延迟?
  16. Java-JPEG图片生成器
  17. django系统发送邮件到用户邮箱,完成验证
  18. 合肥工业大学计算机保研,合肥工大(合肥工业大学保研去向)
  19. 不止防JSON技术绕过,RASP相比WAF的七大技术优势
  20. 从“游击队”到“正规军”:虾神成长史

热门文章

  1. 官网下载Tomcat教程
  2. GTJ2018如何导出全部工程量_广联达GCCP5.0和GTJ2018软件新版发版通知
  3. ap计算机科学AB难吗,解读AP微积分,BC到底比AB难多少?该如何选择?
  4. MongoDb配置文件中参数及其作用
  5. Java实现KMP代码
  6. mysql wal_我所理解的MySQL之一:基础架构
  7. XML与JSON比较,并用AJAX传输XML/JSON数据
  8. 人性化老人手机设计(一)
  9. 开源全渠道业务中台OMS订单管理系统
  10. MyBatis Plus整合p6spy控制台打印美化格式的sql语句