/*基础的并查集.每读到一个group.把后面的人都合并到第一个.最后查询的时候
记录和0有相同祖先的人数即可.*/
#include <stdio.h>
#define maxn 30001
int f[maxn];
int n,m,k,t,p;
int find(int x)
{
if(f[x]==x) return x;
else
f[x]=find(f[x]);
}
void un(int x,int y)
{
int q=find(x);
int w=find(y);
if(q==w) return;
else
f[w]=q;
}
int main()
{
while(scanf("%d%d",&n,&m)==2&&(m+n))
{
for(int i=0; i<n; i++)
f[i]=i;
while(m--)
{
scanf("%d%d",&k,&t);
for(int i=1;i<k;i++)
{
scanf("%d",&p);
un(t,p);
}
}
int ans=0;
int root=find(0);
for(int i=0;i<n;i++)
{
if(root==find(i)) ans++;
}
printf("%d\n",ans);
}
return 0;
}
分享到:
相关推荐
poj 1611 The Suspects 代码 并查集的应用
poj 1611 The Suspects.md
用最简洁的语言实现了一下并查集,欢迎下载,如有意见或建议可以提出,谢谢大家的支持!:) #include using namespace std; int n,m,k; struct TreeNode { int parent; int num; }T[100000]; void init() //并...
##The Usual Suspects 拼图、发现差异、拖拽匹配等,这些游戏真的很简单,但却是你最终一遍又一遍地做的那种游戏,游戏的常见嫌疑人。 这是一组蓝图,您可以下载源代码并制作自己的游戏。 这些蓝图或模板只是作为一...
pinpointed at Ajax functions, as well as large multi-step tests for the usual suspects: cross-site scripting and injection attacks. This book helps you: Obtain, install, and configure useful-and free-...
The ACM director suspects one of his competitors of reading his correspondece. To prevent other companies from revealing his secret, he decided to use a substitution cipher in all the letters ...
focus their activities, geographically prioritize suspects, and to concentrate saturation or directed patrolling efforts in those zones where the criminal predator is most likely to be active. By ...
By the end of the book, you’ll be able to build tests pinpointed at Ajax functions, as well as large multi-step tests for the usual suspects: cross-site scripting and injection attacks. This book ...
Net<br>Pku acm 3278 Catch That Cow<br>Pku acm 2253 Frogger<br>Pku acm 1062 昂贵的聘礼 Pku acm 1125 Stockbroker Grapevine Pku acm 1611 The Suspects Pku acm 2492 A Bug's Life 更多请访问:...
Summary IBM HeapAnalyzer is a graphical tool ... a similar feature set (finding large dominators, leak suspects, etc.), and the IBM Extensions for Memory Analyzer with product-specific analysis engines.
Collect and validate evidence from suspects and computers and uncover clues that are otherwise difficult Packed with powerful recipes to perform highly effective field investigations Book Description...
A direct link to the latest APK can be found here DiscogsBrowser Native Android app to interact with the Discogs' public API.... This app uses the usual suspects: Dagger2 Retrofit2 Rx
该项目是通过引导的。 您将在下面找到一些有关如何执行常见任务的信息。 您可以在找到本指南的最新版本。目录自动格式化代码更改页面<title>... 使用AJAX请求获取数据与API后端集成节点Ruby on Rails 在开发中...
Memory Analyzer (MAT) The Eclipse Memory Analyzer is a fast and feature-rich Java heap analyzer that helps you find memory leaks and reduce memory ... run a report to automatically extract leak suspects.
quickly calculate the retained sizes of objects, see who is preventing the Garbage Collector from collecting objects, run a report to automatically extract leak suspects. 检测内存泄漏的利器,协助...
机器学习词汇 寻找其他维护者! 很抱歉我没有回应。 :(我去过Cruise公司,为ML infra提供自动驾驶汽车,而且还没有永远审查此回购协议。...# Assumes you have the usual suspects installed: numpy, sc
官网一直下载不了,找这个找了好久,因为生成的dump文件太大不得不用linux..../ParseHeapDump.sh java_pid1089.hprof org.eclipse.mat.api:suspects org.eclipse.mat.api:overview org.eclipse.mat.api:top_components
题目 Telefraud(电信诈骗) remains a ... To stop this crime, you are supposed to write a program to detect those suspects from a huge amount of phone call records. A person must be detected as a sus