单向并查集,问至少给几个点可以遍历全图,连通块数量n,入度为0的点的数量m,取max(n,m)~

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=1e6+;
int father[maxn],isRoot[maxn],T,M,N,u,v,visit[maxn];
void init () {
for (int i=;i<maxn;i++) father[i]=i;
fill (isRoot,isRoot+maxn,);
fill (visit,visit+maxn,);
}
int findfather (int x) {
int a=x;
while (x!=father[x]) x=father[x];
while (a!=father[a]) {
int z=a;
a=father[a];
father[z]=x;
}
return x;
}
void Union (int a,int b) {
int faA=findfather(a);
int faB=findfather(b);
if (faA!=faB) father[faA]=faB;
}
int main () {
while (~scanf ("%d",&T)) {
while (T--) {
init ();
scanf ("%d %d",&N,&M);
for (int i=;i<M;i++) {
scanf ("%d %d",&u,&v);
visit[v]=;
Union (u,v);
}
for (int i=;i<=N;i++) isRoot[findfather(i)]++;
int ans=,ans1=;
for (int i=;i<=N;i++) if (isRoot[i]) ans++;
for (int i=;i<=N;i++) if (!visit[i]) ans1++;
printf ("%d\n",max(ans,ans1));
}
}
return ;
}

HDU3173 Dominos的更多相关文章

  1. [CareerCup] 6.2 Dominos on Chess Board 棋盘上的多米诺

    6.2 There is an 8x8 chess board in which two diagonally opposite corners have been cut off. You are ...

  2. [转]Mathematical Induction --数学归纳法1

    Mathematical Induction Mathematical Induction is a special way of proving things. It has only 2 step ...

  3. CareerCup All in One 题目汇总 (未完待续...)

    Chapter 1. Arrays and Strings 1.1 Unique Characters of a String 1.2 Reverse String 1.3 Permutation S ...

  4. 《转载》化繁为简 如何向老婆解释MapReduce?

    本文转载自http://server.zol.com.cn/329/3295529.html 昨天,我在Xebia印度办公室发表了一个关于MapReduce的演说.演说进行得很顺利,听众们都能够理解M ...

  5. 化繁为简 如何向老婆解释MapReduce?(转载)

    化繁为简 如何向老婆解释MapReduce? 昨天,我在Xebia印度办公室发表了一个关于MapReduce的演说.演说进行得很顺利,听众们都能够理解MapReduce的概念(根据他们的反馈).我成功 ...

  6. 关于MapReduce

    MapReduce是Google提出的一个软件架构,用于大规模数据集(大于1TB)的并行运算.概念“Map(映射)”和“Reduce(归纳)”,及他们的主要思想,都是从函数式编程语言借来的,还有从矢量 ...

  7. MapReduce概念(转)

    昨天,我在Xebia印度办公室发表了一个关于MapReduce的演说.演说进行得很顺利,听众们都能够理解MapReduce的概念(根据他们的反馈).我成功地向技术听众们(主要是Java程序员,一些Fl ...

  8. Logger.error方法之打印错误异常的详细堆栈信息

    一.问题场景 使用Logger.error方法时只能打印出异常类型,无法打印出详细的堆栈信息,使得定位问题变得困难和不方便. 二.先放出结论 Logger类下有多个不同的error方法,根据传入参数的 ...

  9. CareerCup All in One 题目汇总

    Chapter 1. Arrays and Strings 1.1 Unique Characters of a String 1.2 Reverse String 1.3 Permutation S ...

随机推荐

  1. L2-3 名人堂与代金券

    题解 这题的话,每一个人都要占一个排名,即使排名并列了. 对于最后一个排名来说,即使人数超过了指定的k,也要加入. 代码 #include <bits/stdc++.h> using na ...

  2. Go_Context

    如何通知子goroutine退出? 1. 使用全局变量 package main import ( "fmt" "sync" "time" ...

  3. MySQL导入含有中文字段(内容)CSV文件乱码解决方法

    特别的注意:一般的CSV文件并不是UTF-8编码,而是10008(MAC-Simplified Chinese GB 2312),所以再通过Navicat导入数据的时候需要指定的编码格式是10008( ...

  4. arcgis字段计算器

    arcgis字段计算器 一.VB脚本 1.取某字段前几位或者后几位 ) ) 2.合并字段,中间加符号 Dim a if [ZDDM2] ="" Then a= [ZDDM1] el ...

  5. docker 初识1

    学习网址 https://git.oschina.net/yangllsdev/docker-training https://docs.docker.com/engine/installation/ ...

  6. 主席树+二分 p4602

    题意:给出每一种果汁的美味度,价格,升数: m个询问,每个询问给出最高上限的钱g,以及给出最少的w 意思是,最多用g的钱去买最少l的果汁,问能得到的最大美味度: 美味度是取所有果汁中美味度的最小值: ...

  7. vue 获得当前无素并做相应处理

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. Lining Up

    AtCoder - 2271-Lining Up                                                                             ...

  9. dubbo+zookeeper搭建笔记

    参考博客: http://blog.csdn.net/u013142781/article/details/50396621#reply http://blog.csdn.net/u013142781 ...

  10. 计算机二级-C语言-程序填空题-190109记录-对二维字符串数组的处理

    //给定程序,函数fun的功能是:求出形参ss所指字符串数组中最长字符串的长度,将其余字符串右边用字符*补齐,使其与最长的字符串等长.ss所指字符串数组中共有M个字符串,且串长<N. //重难点 ...