ural 1272. Non-Yekaterinburg Subway
来源:互联网 发布:要怎么注销淘宝账号 编辑:程序博客网 时间:2024/06/17 05:39
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1272
题意描述:图里现存两种连接方式(通道):tunnel和bridge,修地铁顾名思义在地下,所以bridge尽量少;那么任务就是用现有的两种通道建立连通图,给出需要的最少的bridge数;
思路就是并查集,先用tunnel合并,再用bridge合并;
AC代码:
#define _CRT_SECURE_NO_WARNINGS#include <iostream>#include <stdio.h>#include <string>#include <algorithm>#include <vector>#include <queue>#include <cmath>#include <map>using namespace std;struct Node{int x, y;};vector<int>parent;int getParent(int num){return num == parent[num] ? num : parent[num] = getParent(parent[num]);}bool link(Node *node){int a = getParent(node->x);int b = getParent(node->y);if (a != b){parent[a] = b;return true;}return false;}void func(){int N, T, B;cin >> N >> T >> B;for (int i = 0; i <= N; i++)parent.push_back(i);Node node;for (int i = 0; i < T; i++){cin >> node.x >> node.y;link(&node);}int ans = 0;for (int i = 0; i < B; i++){cin >> node.x >> node.y;if (link(&node))ans++;}cout << ans << endl;}int main(){freopen("out.txt", "w", stdout);freopen("in.txt", "r", stdin);func();}
0 0
- ural 1272. Non-Yekaterinburg Subway
- Ural1272-Non-Yekaterinburg Subway
- URAL 1272 Non-Yekaterinburg Subway (查并集)
- 【神题】URAL 1575 Yekaterinburg Subway 2
- URAL 1314. Chase in Subway
- Subway
- Subway
- Subway
- URAL
- 【ural】
- URAL
- URAL
- URAL
- URAL
- URAL
- URAL
- URAL
- URAL
- Timber
- 黑马程序员03数组排序与二分法查找
- MyBatis拦截器实现mysql与oracle共用分页
- Android内存分析工具(四):adb命令
- 【面试题之算法部分】最长回文子串
- ural 1272. Non-Yekaterinburg Subway
- Spring拦截器中通过request获取到该请求对应Controller中的method对象
- WebService为什么不如RESTful API流行
- MySQL数据库默认编码查看/修改
- Opencv图像显示
- 解决U盘的写保护
- android学习之ListView下拉刷新
- spark-submit
- 树链剖分详解 模板