sdut 2805(最小生成树)
大家快来A水题
Time Limit: 1000MS Memory limit: 65536K
题目描写叙述
输出
演示样例输入
- 3 1
- 1 2
- 3 2
- 1 2
- 1 3
演示样例输出
- 2
- 1
- #include <bits/stdc++.h>
- using namespace std;
- int f[21000];
- int n,m;
- int Find(int x)
- {
- int r = x;
- while(r != f[r])
- r = f[r];
- return r;
- }
- //int Find(int x)
- //{
- // return x == f[x] ?
- x : Find(f[x]);
- //}
- void Link(int a, int b)
- {
- int fx = Find(a);
- int fy = Find(b);
- if(fx != fy)
- f[fx] = fy;
- }
- int main()
- {
- while(~scanf("%d%d",&n,&m))
- {
- for(int i=1;i<=n; i++)
- f[i] = i;
- int a, b;
- while(m--)
- {
- cin>>a>>b;
- Link(a, b);
- }
- int ant = 0;
- for(int i=1; i<=n; i++)
- {
- if(f[i] == i)
- ant++;
- }
- printf("%d\n",ant);
- }
- return 0;
- }
sdut 2805(最小生成树)的更多相关文章
- SDUT图结构练习——最小生成树
http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2144&cid=1186 这道题一开始是用prim算法做的,一直错一直错,后来问了帅郭改用 ...
- SDUT 2933-人活着系列Streetlights(最小生成树Kruskal+和理查德设置来实现)
人活着系列之Streetlights Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描写叙述 人活着假设是为了家庭,亲情----能够说 ...
- SDUT OJ 数据结构实验之图论六:村村通公路(最小生成树)
数据结构实验之图论六:村村通公路 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descri ...
- 数据结构实验之图论九:最小生成树 (SDUT 2144)
#include<bits/stdc++.h> using namespace std; typedef long long ll; struct node { int s, e; int ...
- Electrification Plan(最小生成树)
http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=50#problem/D 最小生成树模板,注意的是这里有k个发电站,它们不再需要连 ...
- prim算法,克鲁斯卡尔算法---最小生成树
最小生成树的一个作用,就是求最小花费.要在n个城市之间铺设光缆,主要目标是要使这 n 个城市的任意两个之间都可以通信,但铺设光缆的费用很高,且各个城市之间铺设光缆的费用不同,因此另一个目标是要使铺设光 ...
- 最小生成树(kruskal模版 Prim模板)
http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2144&cid=1186 最小生成树,最重要的是了解思想 稠密图用Prim,稀疏图用Kru ...
- 最小生成树(Kruskal算法-边集数组)
以此图为例: package com.datastruct; import java.util.Scanner; public class TestKruskal { private static c ...
- 最小生成树计数 bzoj 1016
最小生成树计数 (1s 128M) award [问题描述] 现在给出了一个简单无向加权图.你不满足于求出这个图的最小生成树,而希望知道这个图中有多少个不同的最小生成树.(如果两颗最小生成树中至少有一 ...
随机推荐
- [NOI2002] Robot 解题报告(数论+DP)
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1408 Description 3030年,Macsy正在火星部署一批机器人. 第1秒,他 ...
- 前端验证银行卡(Luhn校验算法)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- hp服务器安装exsi5.5
启动按f8进入raid制造页面: 1. 插入exsi5.5光盘 2. 按下开机键(开机比较慢需要等待一段时间) 3. 进入启动项目界面(插入光盘后启动会让你选择启动项.选择1光盘启动) 接下来按 ...
- iOS ReactiveCocoa 最全常用API整理(可做为手册查询)
本文适合有一定RAC基础的童鞋做不时的查询,所以本文不做详细解释. 一.常见类 1.RACSiganl 信号类. RACEmptySignal :空信号,用来实现 RACSignal 的 +empty ...
- bzoj1457: 棋盘游戏 SG函数 Nim
Code: #include<cstdio> #include<cstring> using namespace std; #define maxn 1003 #define ...
- CSS动画框架Loaders.css +animate.css
CSS加载动画框架Loaders.css 是一款非常出色的加载动画框架,Loaders.css利用纯CSS可以实现很多种样式的Loading加载动画,这些动画并不需要图片来辅助,而是仅仅需要CSS即可 ...
- MySql中允许远程连接
要达到这个目的需要实现两点 开通用户权限 解除本地绑定 开通用户权限 首先登陆服务器端的mysql //不使用空格可以直接登陆 mysql -u用户名 -p密码 mysql> use mysql ...
- 赋值、复制构造函数和构造函数 & 异常安全的赋值
异常安全的赋值 需要注意,复制赋值和复制构造,相兼容. 赋值时候,要带上自检查.
- HDU 1520 Anniversary party(DFS或树形DP)
Problem Description There is going to be a party to celebrate the 80-th Anniversary of the Ural Stat ...
- Understanding IIS Bindings, Websites, Virtual Directories, and lastly Application Pools
In a recent meeting, some folks on my team needed some guidance on load testing the Web application ...