`
yuanlanjun
  • 浏览: 1186053 次
文章分类
社区版块
存档分类
最新评论

The Suspects 并查集基础

阅读更多
/*基础的并查集.每读到一个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 代码 并查集的应用

    poj 1611 The Suspects.md

    poj 1611 The Suspects.md

    ACM ZJU 1789 Suspects

    用最简洁的语言实现了一下并查集,欢迎下载,如有意见或建议可以提出,谢谢大家的支持!:) #include using namespace std; int n,m,k; struct TreeNode { int parent; int num; }T[100000]; void init() //并...

    phaser-the-usual-suspects:那些你看过一百万次的游戏,现在有了 Phaser

    ##The Usual Suspects 拼图、发现差异、拖拽匹配等,这些游戏真的很简单,但却是你最终一遍又一遍地做的那种游戏,游戏的常见嫌疑人。 这是一组蓝图,您可以下载源代码并制作自己的游戏。 这些蓝图或模板只是作为一...

    Web Security Testing Cookbook

    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-...

    ZOJ Problem Set – 2003 Substitution Cipher

    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 ...

    A Methodological Model

    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 ...

    Web Security Testing Cookbook: Systematic Techniques to Find Problems Fast

    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 ...

    poj经典数据结构题目解题报告

    Net&lt;br&gt;Pku acm 3278 Catch That Cow&lt;br&gt;Pku acm 2253 Frogger&lt;br&gt;Pku acm 1062 昂贵的聘礼 Pku acm 1125 Stockbroker Grapevine Pku acm 1611 The Suspects Pku acm 2492 A Bug's Life 更多请访问:...

    ha457-2021-5-12.jar.zip

    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.

    Windows Forensics Cookbook

    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...

    Android代码-DiscogsBrowser

    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

    unusual-suspects

    该项目是通过引导的。 您将在下面找到一些有关如何执行常见任务的信息。 您可以在找到本指南的最新版本。目录自动格式化代码更改页面&lt;title&gt;... 使用AJAX请求获取数据与API后端集成节点Ruby on Rails 在开发中...

    MemoryAnalyzer-1.2.0.20120530-win32.win32.x86_64.zip

    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.

    MemoryAnalyzer-1.7.0.20170613-macosx.cocoa.x86_64.zip

    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. 检测内存泄漏的利器,协助...

    ml-glossary:机器学习词汇

    机器学习词汇 寻找其他维护者! 很抱歉我没有回应。 :(我去过Cruise公司,为ML infra提供自动驾驶汽车,而且还没有永远审查此回购协议。...# Assumes you have the usual suspects installed: numpy, sc

    MemoryAnalyzer-1.9.1.20190826-linux.gtk.x86_64.zip

    官网一直下载不了,找这个找了好久,因为生成的dump文件太大不得不用linux..../ParseHeapDump.sh java_pid1089.hprof org.eclipse.mat.api:suspects org.eclipse.mat.api:overview org.eclipse.mat.api:top_components

    19春第三题 PAT甲级 1158 Telefraud Detection (25分) 用这个方法最好

    题目 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

Global site tag (gtag.js) - Google Analytics