hdu1213
来源:互联网 发布:yy免费协议软件 编辑:程序博客网 时间:2024/05/29 07:56
最简单的并查集。
2015.10.5:
hahaha
#include<stdio.h>#include<string.h>#include<iostream>using namespace std;#define N 1010int fa[N];int root(int x){ if(fa[x]==x){ return x; } else{ fa[x]=root(fa[x]); return fa[x]; }}int main(){ int t; int n,m; int a,b; int ans; scanf("%d",&t); while(t--){ scanf("%d%d",&n,&m); for(int i=1;i<=n;i++){ fa[i]=i; } ans=n; for(int i=1;i<=m;i++){ scanf("%d%d",&a,&b); int ra=root(a); int rb=root(b); if(ra==rb){ continue; } else{ ans--; fa[ra]=rb; } } printf("%d\n",ans); }}
0 0
- hdu1213
- HDU1213
- HDU1213
- hdu1213
- hdu1213
- HDU1213
- hdu1213
- hdu1213
- hdu1213
- HDU1213
- hdu1213
- hdu1213+hdu1232
- HDU1213:How Many Tables
- HDU1213--How Many Tables
- hdu1213-How Many Tables
- hdu1213 How Many Tables
- hdu1213 How Many Tables
- HDU1213 How Many Tables
- Android 图片缓冲的管理-内存缓存
- MongoDB索引与性能
- 线性表
- Objective-C 基础知识之 (十六):内存管理原则一
- 大家好我又滚回来了
- hdu1213
- shell脚本学习 三
- 257 Binary Tree Paths
- 《机器学习与R语言》读书笔记1:机器学习简介
- STL学习之vector容器
- TestCase V2.0版本
- 讯飞语音万能五笔超强手写3合1输入法:
- Objective-C 基础知识之 (十七):内存管理原则二
- C#编写NotifyIcon 将窗口最小化到托盘