USTC campus network is a huge network. There is a bi-directional link between every pair of computers in the network. One of the computers is the BBS server, which is so popular that thousands of people log on it every day. Recently some links of the network are damaged by the rainstorm. The network administrator is going to check which computers are still connected with the BBS server directly or indirectly.

You are to help the administrator to report the number of computers still connecting with the BBS server (not including itself).

InputThe input consists of multiple test cases. Each test case starts with a line containing two integers N and M (1 ≤ N ≤ 10,000, 0 ≤ M ≤ 1,000,000), which are the number of computers and the number of damaged links in USTC campus network, respectively. The computers are numbered from 1 to N and computer 1 is the BBS server. 
Each of the following M lines contains two integers A and B(1 ≤ A ≤ N, 1 ≤ B ≤ N, A ≠ B), which means the link between computer A and B is damaged. A link will appear at most once.

The last test case is followed by a line containing two zeros.OutputFor each test case, print a line containing the test case number( beginning with 1) followed by the number of computers still connecting with the BBS server.Sample Input

3 2
1 2
1 3
4 3
1 2
3 2
4 2
0 0

Sample Output

Case 1: 0
Case 2: 2 要用邻接表存一下不能走的地方,然后预处理一下,直接用二维的数组存会MLE,还有尽量用C++交,G++容易T
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<cmath>
#define Inf 0x3f3f3f3f const int maxn=1e4+;
typedef long long ll;
using namespace std; bool book[maxn];
bool vis[maxn];
vector<int>vec[maxn];
int n,m;
int bfs()
{
queue<int>q;
book[]=true;
q.push();
int ans=;
while(!q.empty())
{
int tmp=q.front();
q.pop();
memset(vis,false,sizeof(vis));
for(int t=;t<vec[tmp].size();t++)
{
vis[vec[tmp][t]]=true;
}
for(int t=;t<=n;t++)
{
if(vis[t]==false&&book[t]==false)
{
ans++;
q.push(t);
book[t]=true;
}
}
}
return ans;
}
int main()
{
int cnt=;
while(scanf("%d%d",&n,&m)!=EOF)
{
if(n==&&m==)
{
break;
}
for(int t=;t<=n;t++)
{
vec[t].clear();
}
memset(book,false,sizeof(book));
int a,b;
for(int t=;t<m;t++)
{
scanf("%d%d",&a,&b);
vec[a].push_back(b);
vec[b].push_back(a);
}
int ans=bfs();
printf("Case %d: %d\n",cnt++,ans); } return ;
}

最新文章

  1. Java中的值传递和引用传递
  2. web攻防
  3. Nginx反向代理设置 从80端口转向其他端口
  4. MySQL 性能优化的最佳20多条经验分享[转]
  5. Ant学习-002-ant 执行 TestNG 测试用例时 [testng] java.lang.NoClassDefFoundError: com/beust/jcommander/ParameterException 解决方案
  6. c++回调
  7. 以莫泰的形式进行页面转换(传值用block)
  8. spring mvc 拦截器
  9. Android开发之实用小知识点汇总-2
  10. OpenCV -- 获取轮廓照片
  11. java定义类 对象,引用,指针
  12. 网络流(最大流)CodeForces 512C:Fox And Dinner
  13. 使用vue-cli构建多页面应用+vux(三)
  14. Kotlin 扩展——省略findViewById
  15. java解析HTML之神器------Jsoup
  16. IE高级配置中,存在SSL支持协议,例如SSL TLS。
  17. asp.net MVC 上传文件 System.Web.HttpException: 超过了最大请求长度
  18. LeetCode--No.001 Two Sum
  19. libcurl使用easy模式阻塞卡死等问题的完美解决
  20. AOP如何在业务结束时,根据参入参数和返回结果添加日志

热门文章

  1. demo1 动态显示view或弹框 动态隐藏view或弹框
  2. c++中包含string成员的结构体拷贝导致的double free问题
  3. CSS可见格式化模型
  4. 前端面试 vue 部分 (3)——v-show和v-if的区别
  5. 【Linux】linux history命令执行后显示历史命令执行时间
  6. C#LeetCode刷题之#617-合并二叉树​​​​​​​​​​​​​​(Merge Two Binary Trees)
  7. Android 开发学习进程0.14 Bindview recyclerview popwindow使用 window类属性使用
  8. Golang笔记整理--第二天
  9. 使用Axure设计基于中继器的左侧导航菜单
  10. 笔记:html基础