MyACM
来源:互联网 发布:信息监理前景知乎 编辑:程序博客网 时间:2024/05/16 05:21
DG之社团调查
时间限制: 1 Sec 内存限制: 128 MB题目描述
自从进了大学,DG发现周围所有的同学几乎都进了社团,他十分想知道同学们究竟都参加了多少个不同的社团。但是DG觉得直接问同学参加了什么社团不够礼貌,因为那样就显得自己对同学不够关心了解。于是聪明的DG想到了另外一种问法:“A和B是否是同一个社团?”。这样一来虽然DG不能直接得到同学参加社团的信息,但是他可以从这次些关系中统计出周围人所参与的社团的个数(假如每个同学最多只能参加一个社团,没有人参加的社团不用考虑)。要么,你也来试一试?
输入
输入包含多组测试数据;
每组测试数据的第一行包含两个整数n,m。其中n表示总人数。接下来有m行,每行有两个整数i,j,表示i,j两人同属于一个社团; (0 < n <= 50000,0 <= m <= n(n-1)/2)
当n=m=0时输入结束。
输出
对于每组测试样例输出一行,表示被询问到的人最多参加了多少个不同的社团。
样例输入
10 9
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
10 4
2 3
4 5
4 8
5 8
0 0
样例输出
1
7
提示:
#include <stdio.h>
int main()
{
int a, b;
scanf("%d %d", &a, &b);
while (0!=a && 0!=b)
{
int n=a,m=b;
int *person = new int[n];
for (int i = 0; i < n; i++)person[i] = 0;
int stID = 0;
while (0!=m--)
{
scanf("%d %d", &a, &b);
if (0!=person[a-1])
{
person[b-1]=person[a-1];
}
else
{
if (0!=person[b-1])
{
person[a-1]=person[b-1];
}
else
{
person[a-1]=person[b-1]=1+stID++;
}
}
}
for (i=0; i<n;i++)
if (0==person[i])
stID++;
printf("%d\n", stID);
scanf("%d %d", &a, &b);
}
return 0;
}
int main()
{
int a, b;
scanf("%d %d", &a, &b);
while (0!=a && 0!=b)
{
int n=a,m=b;
int *person = new int[n];
for (int i = 0; i < n; i++)person[i] = 0;
int stID = 0;
while (0!=m--)
{
scanf("%d %d", &a, &b);
if (0!=person[a-1])
{
person[b-1]=person[a-1];
}
else
{
if (0!=person[b-1])
{
person[a-1]=person[b-1];
}
else
{
person[a-1]=person[b-1]=1+stID++;
}
}
}
for (i=0; i<n;i++)
if (0==person[i])
stID++;
printf("%d\n", stID);
scanf("%d %d", &a, &b);
}
return 0;
}
- MyACM
- Myacm Triangles
- Myacm Triangles
- ZOJ 1704 Myacm Triangles
- pku1569 Myacm Triangles
- UVa 10112 Myacm Triangles
- uva10112 Myacm Triangles
- poj1569 Myacm Triangles
- uva 10112 - Myacm Triangles
- UVA-10112 - Myacm Triangles
- UVA 10112-Myacm三角形
- UVa 10112 - Myacm Triangles
- UVa 10112 - Myacm Triangles
- UVA 10112 Myacm三角形
- 10112 - Myacm Triangles
- Hoj 2485 Myacm Triangles
- Uva 10112 - Myacm Triangles
- uva 10112 Myacm Triangles
- TLD(Tracking-Learning-Detection)学习与源码理解之(一)
- iOS 5 Icon Sizes and Names (New iPad)
- FileZilla FTP服务器源代码分析13
- Java中的监听器
- TLD(Tracking-Learning-Detection)学习与源码理解之(二)
- MyACM
- MySQL + PHP的模式在大并发压力下导致MySQL中存在大量僵死进程
- 多线程—01
- 单链表相关操作代码
- TLD(Tracking-Learning-Detection)学习与源码理解之(三)
- js获取网页高度
- EPOLL的ET和LT模式
- mssql数据库系统日常维护关键信息提取
- oracle 字符串拼接