HDU 1213 How many table(dfs)
来源:互联网 发布:自私的基因 知乎 编辑:程序博客网 时间:2024/06/05 16:21
#include<iostream>using namespace std;const int maxn=1000+5;bool map[maxn][maxn],used[maxn];int n,m;void dfs(int u){ for(int v=1;v<=n;v++){ if(map[u][v]&&!used[v]){ used[v]=true; dfs(v); } }}int main(){ int t; scanf("%d",&t); while(t--) { memset(map,false,sizeof(map)); scanf("%d%d",&n,&m); for(int i=1;i<=m;i++){ int u,v; scanf("%d%d",&u,&v); map[u][v]=map[v][u]=true; } int ans=0; memset(used,false,sizeof(used)); for(int i=1;i<=n;i++){ if(!used[i]) {ans++;dfs(i);} } printf("%d\n",ans); } return 0;}
0 0
- HDU 1213 How many table(dfs)
- Hdu-1213 How many table
- HDU 1978 How many ways(dfs)
- hdu 1213 how many tables
- hdu 1213 How Many Tables
- hdu 1213 How Many Tables
- HDU 1213 How Many Tables
- hdu 1213 How Many Tables
- HDU 1213 How Many Tables
- hdu 1213 How Many Tables
- Hdu 1213 How Many Tables
- hdu 1213 How Many Tables
- hdu 1213 How Many Tables
- HDU 1213 how many tables
- hdu 1213 How Many Tables
- hdu 1213how many tables
- hdu 1213 How Many Tables
- Hdu 1213 - How Many Tables
- Android TableLayout 表格布局
- 欢迎使用CSDN-markdown编辑器
- 半数单集问题
- multiset与set
- Git + SourceTree
- HDU 1213 How many table(dfs)
- 苹果菜单靠近变大-原生JS详解
- 源码阅读1-Object
- 有重复元素的排列问题
- 算法之路二:刘汝佳算法竞赛入门经典 组合数和素数判定
- Selector使用相关:
- 单提交表格中某行数据但是不刷新页面
- 对象转型
- JUnit 单元测试基本用法