CodeForces731C 并查集

低功耗边缘设备部署指南:YOLO26 INT8量化与TensorRT加速全流程 将YOLO26 INT8部署到低功耗边缘设备,核心原则是“校准为王、敏感层精准回退、端到端验证”。校准集≥500张,来自真实推理场景,未经训练增强校准集预处理与推理pipeline逐行对齐trtexec命令必带--fp16作为fallback量化后用polygraphy定位敏感层,而非盲猜仅回退必要层(通常2-3个),保留INT8收益在真实部署场景测试集上验证mAP,不以COCO为准C++部署使用异步推理+双缓冲nsys profiling确认无传输瓶颈。 阅读详情

C. Socks
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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 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.

Input
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 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 ≤ n, li ≠ 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.

这题是见过的最奇怪的并查集….
思路是把小集合并入大集合中….
这么做的原因是即便是同颜色也不一定同集合..
很容易让人搞混
还有一个关键点是
如果一个点被用了两次
那么他必然最后的结果是第二种颜色..
这样的时候就会发现,他的第一种状态在染成第二种颜色的时候没法保证
所以将他爹也染成这个颜色,由于在同一个集合内,有一个没法保证其他的就都没法保证….
所以全体染成这个色
这样就简化成
如何合并集合操作最少了…

#include<iostream>
#include<cstdio>
#include<memory.h>
#include<vector>
#include<algorithm>
using namespace std;
vector <int> q[200001];
int tu[250000], die[250000], jilu[250000];
int zhao(int x)
{
    if (x == die[x])return x;
    else return die[x] = zhao(die[x]);
}
int main()
{
    int n, m, k;
    cin >> n >> m >> k;
    for (int a = 1;a <= n;a++)scanf("%d", &tu[a]), die[a] = a;
    int sum = 0;
    int e, w;
    for (int a = 1;a <= m;a++)
    {
        scanf("%d%d", &e, &w);
        int qd = zhao(e), wd = zhao(w);
        die[qd] = wd;
    }
    for (int a = 1;a <= n;a++)q[zhao(die[a])].push_back(a);
    for (int a = 1;a <= n;a++)
    {
        if (!q[a].size())continue;
        int gagaga = 0;
        for (int b = 0;b<q[a].size();b++)
        {
            jilu[tu[q[a][b]]]++;
            gagaga = max(gagaga, jilu[tu[q[a][b]]]);
        }
        for (int b = 0;b<q[a].size();b++)
        {
            jilu[tu[q[a][b]]]--;
        }
        sum += q[a].size();
        sum -= gagaga;
    }
    cout << sum << endl;
    return 0;
}
2026年03月CCF-GESP编程能力等级认证C++编程一级真题解析 本文收录于专栏《。订阅后可阅读专栏内所有文章。 阅读详情

相关推荐

DBeaver 实战:手动配置 PostgreSQL JDBC 驱动的高级技巧

本文详细介绍了在DBeaver中手动配置PostgreSQL JDBC驱动的高级技巧。针对企业内网、多版本数据库兼容等场景,从获取官方驱动文件、创建自定义驱动配置,到使用Maven坐标管理、连接参数调优及解决常见连接问题,提供了完整的实战指南,帮助开发者实现对数据库连接环境的精准掌控。

apple5的专栏 841

js混淆加密实战,记录一下以备后用

js混淆加密

极简之美,独具匠心。 1万+

LabVIEW电压信号采集系统:从零搭建到科研实战

本文详细介绍了如何从零开始搭建一个基于LabVIEW的电压信号采集系统。内容涵盖硬件选型(如NI USB-6002数据采集卡)、软件环境配置、核心程序开发(包括多通道同步采集、数据自动保存)以及高级功能优化。系统支持自定义采样率与时长,并提供了完整的LabVIEW程序框图和配套的Python数据分析脚本,旨在帮助科研人员和工程师快速构建稳定、高效的专属数据采集方案,提升实验自动化水平。

gold8的专栏 466

佐藤ひろ美 - わたしのそらのいろ

[ti:こころのカケラ] [ar:佐藤ひろ美] [al:わたしのそらのいろ] [by:] [00:01.00]こころのカケラ [00:03.00]歌:佐藤ひろ美(佐藤裕美) [00:05.00]作词:佐藤裕美 作编曲:藤间仁 [00:08.00]OVA 「みずいろ」PinkPineapple ED [00:11.00] [00:21.80]心のかけら 探すように 君の事 探し続け

暮然回首,那人却在灯火阑珊处 2万+

绕开华为通道,获取解锁码解锁BootLoader

刷机有风险,操作需谨慎,如果因为各种因素导致手机变砖无法开机,本教程概不负责,望悉知 前言 这篇文章的大多内容是根据我自己找的一篇文章《绕开华为通道,获取解锁码解锁BootLoader》来编写的,里面的大部分内容是文章的原内容。下面的都是我参考文章中做了一些小部分的修改,增加了我华为P8手机的一些操作,下面开始讲述我的解锁过程。 因为华为官方在2018年的七八月份吧,关闭了解锁码的申请通道,这...

Martin.Mu `s Special Column 5万+

OpenHarmony实战开发-如何实现文件分布式同步编辑

在分布式文件场景中,分布式设备管理包含了分布式设备搜索、分布式设备列表弹窗、远端设备拉起三部分。首先在分布式组网内搜索设备,然后把设备展示到分布式设备列表弹窗中,最后根据用户的选择拉起远端设备。两台设备组网的分布式场景是工作中常常需要的。这样的分布式场景有助于加快工作效率,减少工作中的冗余,本例将为大家介绍如何实现上述功能。​ (2)订阅分布式数据变化:通过this.distributedObject.on(‘status’, this.statusCallback)监听分布式数据对象的变更。

2401_82546228的博客 759

Base64资源

Base64资源。

qq_43557302的博客 3万+

INS/伪距组合导航(1)

星间单差GNSS/INS伪距紧组合

u014430081的博客 880

JavaScript代码规范(常用)

JavaScript代码规范 注:新手一枚,本篇博客为了给自己的学习做个记录,若有表述错误或其他错误欢迎指正,谢过各位了 ![手动抱拳] 1.嵌入规则 JavaScript程序应尽量放在.js文件中,需要调用的时候在html文件中以script标签的形式包含进来,避免在html文件中直接编写JavaScript代码<script src="filename.js"> 2.空格与...

wmdydxr的博客 4517

199、影像技术 roadmap 规划:未来移动影像的技术趋势与芯片算力展望

本文探讨了未来移动影像技术的发展趋势与芯片算力规划。作者从实际案例出发,指出影像技术演进需平衡传感器、ISP、算力和功耗。文章分为三部分:1)传感器将从堆像素转向提升信息密度,重点关注双层晶体管结构、混合快门和多光谱技术;2)ISP架构将向可编程计算单元转型,强调神经网络加速、硬件化多帧融合和语义处理;3)芯片算力瓶颈在于数据搬运,需优化存算一体架构、专用DMA和统一内存。最后给出五点建议:避免盲目追高像素、重视持续功耗、平衡ISP灵活性、预留算力余量、加强传感器与ISP协同设计。作者强调,影像技术的突破在

sundong_81的博客 62

YOLOv8安防监控实战:跌倒/闯入/徘徊实时检测(附TensorRT加速+声光报警部署代码)

精准性:针对跌倒/闯入/徘徊的行为特征优化,准确率达89.3%,误报率低于5次/天;实时性:TensorRT加速到50+FPS,报警延迟<1秒,满足安防“黄金响应时间”;低成本:无需专用AI芯片,RTX 3060或Jetson Orin就能跑,硬件成本比传统方案低60%;易部署:代码全开源,提供从模型训练到硬件联动的完整流程,2天即可搭起原型系统。如果你的安防监控还在“漏报误报”“响应慢”,建议先从跌倒检测的姿态过滤改起——用100张样本测试,再集成TensorRT加速,90%能看到明显改善。

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 682

signature=7691edd593486854c28b40e35668e486,bff-demo-1/yarn.lock at master · wen911119/bff-demo-1 · G...

# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.# yarn lockfile v1"@babel/cli@^7.8.4":version "7.8.4"resolved "https://registry.yarnpkg.com/@babel/cli/-/cli-7.8.4.tgz#505fb053721a98777...

weixin_36310396的博客 12万+

LLM的MCP协议:初识MCP,搭建第一个MCP Server

MCP(Model Context Protocol),是一个开发的协议,标准化了应用程序如何为大模型提供上下文。MCP提供了一个标准的为LLM提供数据、工具的方式,使用MCP会更容易的构建Agent或者是基于LLM的复杂工作流。

Criss@陈磊 2万+

Codeforces 731C:Socks(并查集)

http://codeforces.com/problemset/problem/731/C 题意:有n只袜子,m天,k个颜色,每个袜子有一个颜色,再给出m天,每天有两只袜子,每只袜子可能不同颜色,问要让每天的袜子是相同颜色的,要重新染色的袜子数最少是多少。 思路:并查集合并,将同一天的袜子合并起来,然后就形成了cnt个集合,每个集合都是独立的,因此排序,找出每个集合里面袜子颜色相同的最多的是...

weixin_30421525的博客 201

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

【并查集+贪心】 CodeForces - 731C - Socks

【并查集+贪心】 CodeForces - 731C - Socks 输入第一行一个zz有n只袜子,要在接下来的m天穿,袜子有k种颜色 第二行是n只袜子的颜色 接下来m行是每天穿的两只袜子的编号输出至少要改变几只袜子的颜色才能使这个zz不会因为穿了两只不同颜色的袜子而被嘲笑

xuziling_的博客 338

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

codeforces 731c Socks 并查集

A - Socks Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Description Arseniy is already grown-up and independent. His mother decided to l

WA是一笔财富 447

CodeForces 731C Socks 并查集

//http://codeforces.com/problemset/problem/731/C#include<bits/stdc++.h> using namespace std; const int MAX=2e5+5; int N,M,K,Color[MAX],pre[MAX],num[MAX]; vector<int> G[MAX]; int Find(int x) { int r

Katapeltes 373

Codeforces 731C Socks 并查集

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 m

a7f650ebd327889c的博客 294

Codeforces731C-Socks(并查集)

题目链接http://codeforces.com/contest/731/problem/C思路只要两只袜子同时穿,那么就放进一个集合里面,最后统计一下每个集合里面出现颜色最多的,这样这个颜色就可以不改变,这个集合里面的其他袜子全部变成这个颜色细节统计每个集合里面的出现最多的颜色的时候,如果直接用数组来统计会爆内存,于是用的数组+map代码#include <iostream> #include

博客已迁移至:lzed.github.io 465

Codeforces 731C Socks(并查集)

题意:给你n条袜子,一共有k种颜色,要求每天穿的两只袜子颜色相同,求需要最少改多少只袜子的颜色才能满足条件。 把同一天穿的两只袜子利用并查集放到一块,最后形成了一个一个集合,找出每个集合中哪个颜色的袜子最多,再把集合中其他颜色的袜子变成那个颜色,最后把每个集合所求的值加起来就是答案。 #include using namespace std; int type[200005],pre[

ScorpioN___的博客 687

并查集 - Socks - CodeForces - 731C

并查集 - Socks - CodeForces - 731C 题意: 首行输入n,m,k,表示有n条袜子,挑选出m对,共有k种可能的颜色。首行输入n,m,k,表示有n条袜子,挑选出m对,共有k种可能的颜色。首行输入n,m,k,表示有n条袜子,挑选出m对,共有k种可能的颜色。 第二行输入n个数字c1,c2,...,cn,ci表示第i条袜子的颜色。第二行输入n个数字c_1,c_2,...,c_n,c_i表示第i条袜子的颜色。第二行输入n个数字c1​,c2​,...,cn​,ci​表示第i条袜子的颜色。 接着输

njuptACMcxk的博客 234

codeforces 731C 并查集

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 m

qiuxueming_csdn 734

codeforces 731C (并查集 水)

题目链接:点击这里题意:给出n只袜子的颜色,每天选择两只袜子,每次能把一只袜子染色。问最少染色几只袜子能使的每天的袜子颜色一样。给每天穿的两只袜子连边,很显然一个分量的袜子要一起考虑,并查集维护分量就好了。然后搜出最多的颜色,把分量的点都染成这个颜色即可。#include <cstdio> #include <cmath> #include <algorithm> #include <iostrea

morejarphone~ 636

codeforces 731C 并查集+贪心

点击打开链接 利用并查集把颜色要相同的下标放在同一集合中,贪心:找到每个集合中出现最多的颜色 把剩下的颜色变为该颜色即可 ans+=size-mx #include #include #include #include #include #include #include #include using namespace std; const int N=2e5+10; lo

Masamiiiiii 1179

CodeForces 731C Socks (并查集)

题意:n只袜子,穿m天,每只袜子有一种颜色,有k种颜料对袜子染色,接下来的m天每天给你指定两只袜子穿,问现在最少需要染色多少次才能使得接下来的m天每天穿的袜子颜色都相同。注意是一次性染色。 题解:并查集 既然是一次性染色,那么就对所在同一集合的袜子染相同颜色,我们不关心袜子出现几次,所以染的颜色取决于集合中颜色最多的是哪个。 用vector存以根为代表的集合含有的颜色,map存个数,遍历求最多即可。 #define _CRT_SECURE_NO_WARNINGS #include<iostream&g

gongyuandaye的博客 322

codeforces 并查集_CodeForces 731C Socks(并查集)

C. Sockstime limit per test: 2 secondsmemory limit per test: 256 megabytesinput: standard inputoutput: standard outputDescriptionArseniy is already grown-up and independent. His mother decided to leav...

weixin_39950867的博客 191

CodeForces 731C - Socks(并查集)

C. Socks time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Arseniy is already grown-up and independent. His mother decided to leave him alon

Snakeflute的博客 443
上一篇: HDU1045 水dfs....数据量太小了才16.....
下一篇: CodeFoeces732C 枚举
NineFailure
博客等级 码龄11年 22粉丝 317原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值