USACO-Silver-Worm Sort-并查集的应用以及二分优化

本文详细介绍了USACO Silver级别的一道题目,涉及到的问题是如何帮助奶牛通过虫洞快速排序。通过使用并查集维护点的连通性来判断是否能复位,再利用二分查找优化,寻找最大最小虫洞宽度。文章讲解了算法思路,包括判定过程、二分优化,并提供了完整代码和解题总结。
摘要由CSDN通过智能技术生成

一.题面

Farmer John's cows have grown tired of his daily request that they sort themselves before leaving the barn each morning. They have just completed their PhDs in quantum physics, and are ready to speed things up a bit.

This morning, as usual, Farmer John's NN cows (1≤N≤1051≤N≤105), conveniently numbered 1…N1…N, are scattered throughout the barn at NN distinct locations, also numbered 1…N1…N, such that cow ii is at location pipi. But this morning there are also MM wormholes (1≤M≤1051≤M≤105), numbered 1…M1…M, where wormhole ii bidirectionally connects location aiai with location bibi, and has a width wiwi (1≤ai,bi≤N,ai≠bi,1≤wi≤1091≤ai,bi≤N,ai≠bi,1≤wi≤109).

At any point in time, two cows located at opposite ends of a wormhole may choose to simultaneously swap places through the wormhole. The cows must perform such swaps until cow ii is at location ii for 1≤i≤N1≤i≤N.

The cows are not eager to get squished by the wormholes. H

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值