UVA 10608 Friends
题目大意:共有n个人,m对人为已知的朋友关系,而且这种关系具有传递性,也就是A与B,B与C是朋友,可以确定A与C是朋友,求一个人数最多的朋友团体。
bfs就可以了,遇到未访问的结点,加入队列并且朋人数增加,bfs一开始只访问未访问的结点,并作为一个团体的开始。、
代码:
#include <iostream>
#include <cstdio>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#define esp 1e-6
#define pb push_back
#define in freopen("in.txt", "r", stdin);
#define out freopen("out.txt", "w", stdout);
#define print(a) printf("%d\n",(a));
#define bug puts("********))))))");
#define Rep(i, c) for(__typeof(c.end()) i = c.begin(); i != c.end(); i++)
#define inf LLONG_MAX
#define INF 0x0f0f0f0f0f0f
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef vector<int>:: iterator IT;
#define N 30010
#define M 501000
VI g[N], ss;
int vis[N], ans, temp;
void init(void)
{
ans = ;
memset(vis, , sizeof(vis));
}
void bfs(int u)
{
temp = ;
vis[u] = ;
queue<int> q;
q.push(u);
while(!q.empty())
{
int i;
i = q.front();
q.pop();
Rep(k, g[i])
{
if(!vis[*k])
vis[*k] = ,temp++, q.push(*k);
} }
}
int main(void)
{
int T;
for(int t = scanf("%d", &T); t <= T ; t++)
{
for(int i = ; i < N; i++)
g[i].clear();
ss.clear();
init();
int n, m;
scanf("%d%d", &n, &m);
while(m--)
{
int u, v;
scanf("%d%d", &u, &v);
g[u].pb(v);
g[v].pb(u);
ss.pb(u),ss.pb(v);
}
Rep(i, ss)
{
temp = ;
if(!vis[*i])
bfs(*i);
ans = max(temp, ans);
}
printf("%d\n", ans);
}
return ;
}
UVA 10608 Friends的更多相关文章
- uva 10608
简单并查集 水水..... #include <cstdio> #include <cstring> #define maxn 30005 int fa[maxn],ans[ ...
- Disjoint Sets
Disjoint Sets Disjoint Sets的意思是一堆集合們,它們相互之間都沒有交集.沒有交集是指:各個集合之間沒有擁有共同.相同的元素.中文稱作「分離集」. Disjoint Sets的 ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
- UVA&&POJ离散概率与数学期望入门练习[4]
POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...
- UVA计数方法练习[3]
UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...
- UVA数学入门训练Round1[6]
UVA - 11388 GCD LCM 题意:输入g和l,找到a和b,gcd(a,b)=g,lacm(a,b)=l,a<b且a最小 g不能整除l时无解,否则一定g,l最小 #include &l ...
- UVA - 1625 Color Length[序列DP 代价计算技巧]
UVA - 1625 Color Length 白书 很明显f[i][j]表示第一个取到i第二个取到j的代价 问题在于代价的计算,并不知道每种颜色的开始和结束 和模拟赛那道环形DP很想,计算这 ...
随机推荐
- Ubuntu 16.04 - 64bit 访问Windows磁盘报错 he NTFS partition is in an unsafe state. Please resume and shutdown Windows fully (no hibernation ...
今天在打开某个磁盘时,突然报错,报错信息如下 原因:Windows 未正常关闭,导致系统误以为存在临时缓存文件 解决方法: http://www.linuxidc.com/Linux/2014-05/ ...
- C#之装箱和拆箱
在实际编码过程中,有时候会出现装箱和拆箱操作.下面就类分别认识一下: 需要注意的是,类型转换和这个是不同的.Convert方法并没有发生装箱和拆箱操作,而是类型转换,包括int.parse等等. 装箱 ...
- Google maps not working IE11
参考原因: http://www.easypagez.eu/maps/ieworking.html 如果还不行的话,在map的样式上加上width:100%;height:100% ;position ...
- 第十八篇、keychain保存UUID(保持唯一性,应用卸载,下载安装也不变)和获取IP地址
.h #import <Foundation/Foundation.h> #import <Security/Security.h> /**使用**/ //-(void) se ...
- CocoaLumberjack+XcodeColor(输出带有颜色的日志)在安装过程中遇到的问题
在安装的时候遇到了各种坑,(在这里用到的pch文件的使用以及解决无法引入的问题,可以参考上午的文章) 一(XcodeColor的安装).在github上下载XcodeClolor的插件,并且安装,Xc ...
- AbstractExecutorService (未完成)
AbstractExecutorService是一个实现了ExecutorService的抽象类.主要实现了ExecutorService的invoke方法.
- RX学习笔记:在FreeCodeCamp的学习
FreeCodeCamp https://www.freecodecamp.com 2016-07-03 前几日在Github浏览时,偶然看到一个叫FreeCodeCamp的开源项目,进去该网站之后感 ...
- 获取input标签的所有属性
1.用jquery$("input[name='btnAdd']").attr("value") 获取value属性值,其它属性换attr的参数就OK 例1: ...
- c#的多线程
多线程的使用方法: Thread t = new Thread(new ThreadStart (StartMethod)); t.Start(); private void StartMethod( ...
- How to open .ccproj in VS2010?
Q: How to open .ccproj projects types in VS2010, ccproj file type is a Cloud project i suppose. Plea ...