hdu 2463 bfs USTC campus network
来源:互联网 发布:mysql and or 优先级 编辑:程序博客网 时间:2024/06/01 09:01
题意:http://acm.hdu.edu.cn/showproblem.php?pid=2463
原来是一个完全图,去掉一些边,问最后跟1相连的点有几个。
题解:
bfs+数据结构。感觉数据结构还是很神的。用vector存删去的边,用pre去判断和队列顶点相连的点。好神。
#include <iostream>#include <cstdio>#include <vector>#include <cstring>#include <queue>#define maxn 10010using namespace std;int n,m,a,b;int pre[maxn];vector <int> map[maxn];bool vis[maxn];int solve(){ queue <int> q; memset(vis,0,sizeof(vis)); memset(pre,0,sizeof(pre)); vis[1] = 1; q.push(1); int ans = 0; while(!q.empty()){ int now = q.front(); q.pop(); for(int i = 0; i < map[now].size(); i ++) pre[map[now][i]] = now; for(int i = 1; i <= n;i ++) if(!vis[i] && pre[i] != now) vis[i] = true, q.push(i),ans ++; } return ans;}int main(){ int ca = 1; while(~scanf("%d%d",&n,&m) && (n || m)){ for(int i = 1; i <= n; i ++) map[i].clear(); for(int i = 0; i < m; i ++){ scanf("%d%d",&a,&b); map[a].push_back(b); map[b].push_back(a); } printf("Case %d: %d\n",ca ++ ,solve()); } return 0;}
- hdu 2463 bfs USTC campus network
- hdu 2463 USTC campus network (BFS+链表+Hash)
- hdu2463 USTC campus network--BFS & STL
- HDU2463 USTC campus network
- POJ3697-USTC campus network
- POJ--3697[USTC campus network] BFS+hash(O(N^2))
- POJ 3697USTC campus network
- acm pku 3697 USTC campus network
- [HDU2463] USTC campus network [2008 Asia Hefei Regional Contest Online H]
- HDU 4039 The Social Network bfs
- HDU 4804 Campus Design
- Hdu 4804 Campus Design
- Campus Design HDU
- Campus
- How to do when Campus Network doesn't support mentohust
- HDU 4084 Campus Design 状压dp
- hdu 4804 Campus Design (状压dp)
- HDU 4804 Campus Design(插头DP)
- 给盒子的贺文
- Oracle 10.2.0.1 rolling upgrade oracle 10.2.0.5 by Logical Standby
- poj 2513 Colored Sticks
- Java.text包学习笔记
- 佳人有约
- hdu 2463 bfs USTC campus network
- 建立哈希,访问哈希
- C++异常机制的实现方式和开销分析
- Unity3d与iOS的交互(1)
- 倒排索引-搜索引擎的基石
- Oracle 常用 SQL 语句大全
- Win7 64位 Samba共享VirtualBox Ubuntu12.04 下目录 (Samba图形界面)
- c# 选择目录中过滤器的写法
- 紫薇花开的季节(二)