Sicily 4378. connect components in undirected graph
来源:互联网 发布:地脚螺栓计算软件 编辑:程序博客网 时间:2024/05/17 23:06
仍然是宽搜,只不过是多次宽搜,输出宽搜次数即可。
Run Time: 0.01sec
Run Memory: 1168KB
Code length: 1157Bytes
Submit Time: 2011-12-24 11:55:30
// Problem#: 4378// Submission#: 1120874// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/// All Copyright reserved by Informatic Lab of Sun Yat-sen University#include <iostream>#include <queue>#include <cstring>using namespace std;int main(){ int n, m; int i, j; queue<int> q; int count, set; bool visited[ 1001 ]; bool path[ 1001 ][ 1001 ]; memset( visited, false, sizeof( visited ) ); memset( path, false, sizeof( path ) ); cin >> n >> m; while ( m-- ) { cin >> i >> j; path[ i ][ j ] = true; path[ j ][ i ] = true; } count = 0; set = 0; while ( count != n ) { for ( i = 1; i <= n; i++ ) { if ( visited[ i ] == false ) { q.push( i ); visited[ i ] = true; count++; set++; break; } } while ( !q.empty() ) { i = q.front(); for ( j = 1; j <= n; j++ ) { if ( path[ i ][ j ] && !visited[ j ] ) { q.push( j ); visited[ j ] = true; count++; } } q.pop(); } } cout << set << endl; return 0;}
- Sicily 4378. connect components in undirected graph
- Sicily Connect components in undirected graph
- connect components in undirected graph
- Sicily 1002. connected components in undirected graph
- [leetcode323]Number of Connected Components in an Undirected Graph
- LeetCode 323. Number of Connected Components in an Undirected Graph
- leetcode Number of Connected Components in an Undirected Graph
- Number of Connected Components in an Undirected Graph
- Leetcode 323. Number of Connected Components in an Undirected Graph
- LeetCode 323. Number of Connected Components in an Undirected Graph
- LeetCode 323. Number of Connected Components in an Undirected Graph
- Leetcode 323. Number of Connected Components in an Undirected Graph
- No323. Number of Connected Components in an Undirected Graph
- 323. Number of Connected Components in an Undirected Graph
- leetcode323. Number of Connected Components in an Undirected Graph
- sicily connected components in undiected graph
- [leetcode] 323. Number of Connected Components in an Undirected Graph 解题报告
- LeetCode 323. Number of Connected Components in an Undirected Graph(连通分量)
- Tomcat 源代码分析之Socket通讯
- Sicily 4376. shortest path in unweighted graph
- Gentoo硬盘安装
- hadoop 0.20.2 datanode注册有延迟
- Effective C++读书笔记(21)
- Sicily 4378. connect components in undirected graph
- Effective C++读书笔记(22)
- 单精度和双精度数据
- PIL python的一个图像处理库 支持 python3
- Sicily 4379. bicoloring
- Bootstrap的一些笔记——网格系统
- Sicily 4427. Greatest Common Divisors
- Sicily 4431. 有向图边的分类
- How browsers work--Behind the scenes of modern web browsers (前端必读)