当前位置:网站首页>Hangzhou Electric Power Multi-School 6 1010. Planar graph
Hangzhou Electric Power Multi-School 6 1010. Planar graph
2022-08-08 02:33:00 【Strezia】
1010
最小生成树
题意
给出一个 n n n 个点 m m m Side plan,Ask at least how many edges can be removed to make every part of the plane reachable,Output the solution with the minimum number of edges to be deleted and the lexicographical order of the edge numbers.
思路

You can build a dual graph and run itmst,但有更简单的方法.
Drawing and finding satisfaction“Every part of the floor plan is mutually reachable”The picture must be a tree or a forest,(In fact, there must be no loop,Acyclic is a tree),That is, the remaining graph after we delete the edge must be a tree/森林,So run according to the side number from big to trotKruscal就可以了,对第 i i i 号边,If the two connected points are in the same set,Then this edge must be deleted.This satisfies the lexicographical order of the deleted edges as small as possible.
代码
void solve() {
cin >> n >> m;
for(int i = 1; i <= n; i++) {
fa[i] = i;
}
for(int i = 1; i <= m; i++) {
cin >> e[i].u >> e[i].v;
}
vector<int> ans;
for(int i = m; i; i--) {
if(find(e[i].u) == find(e[i].v)) {
ans.pb(i);
}
else {
merge(e[i].u, e[i].v);
}
}
sort(ans.begin(), ans.end());
cout << ans.size() << endl;
for(auto i : ans) {
cout << i << ' ';
}
cout << endl;
}
边栏推荐
- PAT甲级 1061 Dating
- LED驱动程序进一步优化-分层-分离
- Is it safe and reliable to open a securities account?
- 栈的压入、弹出序列
- SIGIR'22 | 广告间排序和广告内创意优选联合优化
- 解决Mysql和redis缓存不一致问题
- SDRAM详解
- NVIDIA NCCL Optimization - Leverage shared memory for faster collective communication than NCCL
- 解决Endnote插入参考文献时导致word闪退问题
- PAT甲级 1055 The World‘s Richest
猜你喜欢

黑马jvm课程笔记d1

杭电多校6 1009. Map

Deep profiling of classes and objects

PAT甲级 1052 Linked List Sorting

【HDLBits 刷题 6】Circuits(2)Sequential Logic---Latches and Filp Flops

一套极简的MQTT使用接口EasyMqttClient

海外元宇宙媒体宣发一定要关注到宣传的整体性

杭电多校6 1010. Planar graph

(Note)航世BOW G19键盘 —— 使用说明书

Octopus Application Chain|Content Curation Collaboration Organization DISCOVOL DAO Mainnet Launched in August
随机推荐
typescript辅助技术
C#《原CSharp》第四回 人常见岁月更替 却难知人文相继
Deep profiling of classes and objects
陈强教授《机器学习及R应用》课程 第四章作业
Is it safe to buy stocks with great wisdom?Will the funds be transferred?
一套极简的MQTT使用接口EasyMqttClient
Case: ELK log analysis system
find prime problem
RV-GAN: Segmentation of retinal vascular structures in fundus photographs using a novel multi-scale generative adversarial network
LED驱动程序进一步优化-分层-分离
陈强教授《机器学习及R应用》课程 第十二章作业
嵌入式分享合集31-串口
LeetCode二叉树系列——144.左叶子之和
【愚公系列】2022年08月 Go教学课程 032-结构体方法继承
Octopus Application Chain|Content Curation Collaboration Organization DISCOVOL DAO Mainnet Launched in August
解决Mysql和redis缓存不一致问题
如何验证期货公司开户的正规性
机器学习笔记 - 基于CNN+OpenCV的图像着色
Embedded Interview Questions
系统滴答及Systick定时器