URAL 1272 Non-Yekaterinburg Subway (查并集)
来源:互联网 发布:江西先锋软件集团 编辑:程序博客网 时间:2024/06/14 19:12
#include<stdio.h>#define MAX_ISLANDS (10000 + 1)#define MAX_TUNELS (12000 + 1)#define MAX_BRIDGES (12000 + 1)struct CONNECTION{int oneIsland;int anotherIsland;};CONNECTION connectionArray[MAX_TUNELS + MAX_BRIDGES];int connectionNum;int islands;int tunels;int bridges;int belongTo[MAX_ISLANDS];int findBelongTo(int island){if (island == belongTo[island])return island;belongTo[island] = findBelongTo(belongTo[island]);return belongTo[island];}int connect(int oneIsland, int anotherIsland){int oneBelongTo = findBelongTo(oneIsland);int anotherBelongTo = findBelongTo(anotherIsland);if (oneBelongTo != anotherBelongTo){belongTo[oneBelongTo] = anotherBelongTo;return 1;}return 0;}int main(){scanf("%d %d %d", &islands, &tunels, &bridges);int island;for (island = 1; island <= islands; island++)belongTo[island] = island;int oneIsland, anotherIsland;int tunel;for (tunel = 1; tunel <= tunels; tunel++){scanf("%d %d", &oneIsland, &anotherIsland);connect(oneIsland, anotherIsland);}int minBridges = 0;int bridge;for (bridge = 1; bridge <= bridges; bridge++){scanf("%d %d", &oneIsland, &anotherIsland);if (connect(oneIsland, anotherIsland))minBridges++;}printf("%d", minBridges);return 0;}
0 0
- URAL 1272 Non-Yekaterinburg Subway (查并集)
- ural 1272. Non-Yekaterinburg Subway
- Ural1272-Non-Yekaterinburg Subway
- 【神题】URAL 1575 Yekaterinburg Subway 2
- ural 1982. Electrification Plan 并查集
- ural 1003 Parity 并查集
- URAL 1003 Parity(并查集)
- Ural 1682 Crazy Professor (并查集)
- ural 1003. Parity(并查集)
- Ural 1003 Parity(并查集)
- Ural 1671. Anansi's Cobweb(并查集)
- poj1733 & Ural 1003 Parity Game (hash+并查集 )
- URAL 1671 Anansi's Cobweb (并查集)
- URAL 1982. Electrification Plan(并查集)
- Pilot Work Experience (URAL 1888 并查集+floyd)
- URAL 2055 Urban Geography 分治,并查集
- URAL 1962 In Chinese Restaurant 并查集
- Ural 1671. Anansi's Cobweb(并查集)
- 远程重启服务器的有效办法?
- 实现pdf图片格式转换成txt文档的方法
- Jquery Mobile入门笔记
- 软工视频第二章之制定计划
- JVM学习之-栈
- URAL 1272 Non-Yekaterinburg Subway (查并集)
- Spring学习(九)使用ioc注解方式配置bean
- springmvc 上传文件
- java异常处理
- java异常总结
- 拉开大变革序幕(上):在浪潮之巅观望Docker
- echart横坐标太长导致坐标显示不完全
- jQuery table行变色
- log4j文件