CF731C.Socks

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 l__i and r__i for each of the days — the indices of socks to wear on the day i (obviously, l__i stands for the left foot and r__i for the right). Each sock is painted in one of k colors.

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.

阿尔塞尼已经长大成人,能够独立生活。他的母亲决定独自外出度假 mm 天,将他一人留在家中。她为阿尔塞尼准备了大量食物、留下了一些钱,并且洗好了他所有的衣服。

在临行前十分钟,她突然意识到:还应为阿尔塞尼在她离开期间的每一天,分别写明具体该穿哪一双袜子。阿尔塞尼一家有点特别,所有衣物均被编号。例如,阿尔塞尼共有 nn 只袜子,每只袜子被赋予一个从 11 到 nn 的唯一整数编号。因此,她只需为每一天 ii 写下两个整数 lil_i 和 rir_i —— 分别表示当天应穿在左脚和右脚上的袜子编号(显然,lil_i 对应左脚,rir_i 对应右脚)。每只袜子被涂上 kk 种颜色之一。

母亲离开后,阿尔塞尼注意到:根据这些指示,他在某些天会穿上两只颜色不同的袜子。这显然是因匆忙而导致的严重错误。阿尔塞尼是个聪明的孩子,并且——出于某种神奇的巧合——他恰好拥有 kk 罐颜料,每罐对应 kk 种颜色中的一种。

阿尔塞尼希望重涂部分袜子的颜色,使得对于全部 mm 天,他都能严格遵循母亲的指示,并且每天所穿的两只袜子颜色相同。由于这几天他将非常忙碌,无法再更改任何袜子的颜色,因此他必须立刻确定所有袜子的最终颜色。

最新发布的电脑游戏《Bota-3》刚刚面世,阿尔塞尼迫不及待想玩。那么,为使他能按母亲的指示,在每一天都穿上同色的两只袜子,最少需要重涂多少只袜子的颜色?

输入格式

The first line of input contains three integers n, m 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 _c_1, _c_2, ..., c__n (1 ≤ c__i ≤ k) — current colors of Arseniy's socks.

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

输入的第一行包含三个整数 nn、mm 和 kk(2 ≤ n ≤ 200 0002 \leq n \leq 200\,000,0 ≤ m ≤ 200 0000 \leq m \leq 200\,000,1 ≤ k ≤ 200 0001 \leq k \leq 200\,000)——分别表示袜子的数量、天数以及可用颜色的种类数。

第二行包含 nn 个整数 c1,c2,…,cnc_1, c_2, \dots, c_n(1 ≤ ci ≤ k1 \leq c_i \leq k)——表示阿塞尼伊当前每只袜子的颜色。

接下来的 mm 行中,每行包含两个整数 lil_i 和 rir_i(1 ≤ li, ri ≤ n1 \leq l_i,\,r_i \leq n,且 li ≠ ril_i \neq r_i)——表示阿塞尼伊在第 ii 天应穿的两只袜子的下标。

输出格式

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.

输出一个整数——为遵守指令且避免人们因看到颜色不同的袜子而发笑,所需改变颜色的袜子的最少数量。

输入输出样例

  • 输入#1

    3 2 3
    1 2 3
    1 2
    2 3

    输出#1

    2
  • 输入#2

    3 2 2
    1 1 2
    1 2
    2 1

    输出#2

    0

说明/提示

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.

在第一个样例中,Arseniy 可以将第一只和第三只袜子重新涂成第二种颜色。

在第二个样例中,无需更改任何颜色。

输入解题思路,AI测评打分。不知道怎么写?

首页