思路:

模板题,一步一步加入集合,最后判断有多少人跟0在同一个集合就行了。

#include<iostream>
#include<cstdio>
using namespace std;
const int manx = 3e4 + 5;
int a[manx];
int find(int x){
return a[x] == x ? x : a[x] = find(a[x]);
}
int main()
{
int n, m, u, v;
while (cin >> n >> m){
if (n == 0 && m == 0) break;
for (int i = 0; i < n; i++) a[i] = i;
while (m--){
int q;
cin >> q >> u;
for (int i = 1; i < q; i++) {
cin >> v;
a[find(u)] = find(v);
u = v;
}
}
int ans = 0;
for (int i = 0; i < n; i++)
if (find(a[i]) == find(0))
ans++;
cout << ans << endl;
}
return 0;
}

POJ - 1611 : The Suspects (普通并查集)的更多相关文章

  1. poj 1611:The Suspects(并查集,经典题)

    The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 21472   Accepted: 10393 De ...

  2. POJ 1611 The Suspects (并查集)

    The Suspects 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/B Description 严重急性呼吸系统综合症( S ...

  3. poj 1611 The Suspects(并查集)

    The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 21598   Accepted: 10461 De ...

  4. POJ 1611 The Suspects(并查集,简单)

    为什么ACM的题意都这么难懂,就不能说的直白点吗?还能不能好好的一起刷题了? 题意:你需要建一个n的并查集,有m个集合,最后要输出包含0的那个集合的元素的个数. 这是简单并查集应用,所以直接看代码吧! ...

  5. poj 1611 The Suspects(简单并查集)

    题目:http://poj.org/problem?id=1611 0号是病原,求多少人有可能感染 #include<stdio.h> #include<string.h> # ...

  6. POJ - 1611 The Suspects 【并查集】

    题目链接 http://poj.org/problem?id=1611 题意 给出 n, m 有n个人 编号为 0 - n - 1 有m组人 他们之间是有关系的 编号为 0 的人是 有嫌疑的 然后和 ...

  7. POJ 1611 The Suspects【并查集】

    解题思路:一共给出 n个人,m组,接下来是m组数据,每一组开头是该组共有的人 num,则接下来输入的num个数,这些数是一组的 又因为最开始只有编号为0的人携带有病毒,且只有同一组的人会相互传染,问最 ...

  8. 并查集 (poj 1611 The Suspects)

    原题链接:http://poj.org/problem?id=1611 简单记录下并查集的模板 #include <cstdio> #include <iostream> #i ...

  9. poj 2236:Wireless Network(并查集,提高题)

    Wireless Network Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 16065   Accepted: 677 ...

  10. [并查集] POJ 1611 The Suspects

    The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 35206   Accepted: 17097 De ...

随机推荐

  1. [CF1168C] And Reachability

    And Reachability 题面翻译 题目描述 Toad Pimple 有一个整数数组 \(a_1,\dots,a_n\). 当 \(x < y\) 且存在 \(x = p_1 < ...

  2. [Ynoi2002] Goedel Machine

    题目描述 由于你不会设计哥德尔机,所以你决定先做一道数据结构题: 给定一个长度为 \(n\) 的序列 \(a_1\cdots a_n\).你需要回答 \(m\) 个询问,第 \(i\) 个询问给定一个 ...

  3. [USACO2007OPEN G]Cheapest Palindrome

    题目描述 Keeping track of all the cows can be a tricky task so Farmer John has installed a system to aut ...

  4. 设备唯一标识方法(Unique Identifier):如何在 Windows 系统上获取设备的唯一标识

    原文地址 设备唯一标识方法(Unique Identifier):如何在 Windows 系统上获取设备的唯一标识 zz 唯一的标识一个设备是一个基本功能,可以拥有很多应用场景,比如软件授权(如何保证 ...

  5. Python subprocess 使用(二)

    Python subprocess 使用(二) 本篇继续介绍subprocess的使用. 这里主要添加两个自己在工作过程中常用的两个小命令. 1: 获取顶层activity import subpro ...

  6. 子类Dog根据自己的需要,重写了Animal方法

    子类Dog根据自己的需要,重写了Animal方法 package com.guoba.method; class Animal{ public void move(){ System.out.prin ...

  7. shell的变量

    变量含义 学生时代所学的数学方程式,如x=1,y=2,那会称之为x,y是未知数 对于计算机角度,x=1,y=2等于定义了两个变量,名字分别是x,y,且赋值了1和2 变量是暂时存储数据的地方,变量临时存 ...

  8. PyTorch项目源码学习(1)

    PyTorch PyTorch是一个开源的深度学习框架,项目地址 https://github.com/pytorch/pytorch 在学术工作中的使用频率较高.其主体由C++开发,PyTorch是 ...

  9. C#数据结构与算法系列(十三):递归——迷宫问题

    1.示例 2.代码实现 public class Maze { public static void Test() { int[][] map = new int[8][]; for (int i = ...

  10. 提升软件质量?为什么不试试华为云CodeArts Check

    摘要:华为云CodeArts Check代码检查服务为用户提供包括代码风格.通用质量与代码安全风险等在内的检查能力,同时提供问题闭环处理.检查报告等功能,从而一站式完成代码检查作业. 本文分享自华为云 ...