杭电的图论题目列表。共计500题,努力刷吧

AC 64ms

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
const int INF = 1e8;
using namespace std;
int father[100010];
bool vis[100010];
int findx(int r)
{
int i = r,j;
while(father[r]!=r)
{
r=father[r];
} while(father[i]!=r)
{
j = father[i];
father[i] = r;
i = j;
}
return r;
} bool Merge(int x,int y)
{
int fx,fy;
fx=findx(x);
fy=findx(y);
if(fx!=fy)
{
father[fx]=fy;
return 1;
}
else
return 0;
}
void init()
{
for(int i=0;i<100010;i++)
{
father[i]=i;
vis[i]=0;
}
}
int main()
{
int a,b;
while(scanf("%d%d",&a,&b)!=EOF)
{
if(a==-1&&b==-1)
break;
int flag=1,t=0;
if(a==0 && b==0)
{
puts("Yes");
continue;
}
init();
int num = 0;
while(1)
{
if(a==0&&b==0) break;
if(flag)
{
if(!vis[a]) num++; //num记录点数
if(!vis[b]) num++;
vis[a]=1; vis[b]=1;
if(Merge(a,b)==1)
t++; //t记录边数
else
flag = 0;
}
scanf("%d%d",&a,&b);
}
if(num-t==1 &&flag == 1)//满足题意的仅仅能是 点数-边数==1
puts("Yes")
else
puts("No");
}
return 0;
}

HDU1272 小希的迷宫(基础并查集)的更多相关文章

  1. hdu1272 小希的迷宫 基础并查集

    #include <iostream> #include <cstdlib> #include <cstdio> #include <algorithm> ...

  2. hdu1272 小希的迷宫【并查集】

    上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardon来走.但是她设计迷宫的思路不一样,首先她认为所有的通道都应该是双向连通的,就是说如果有一个通道连通了 ...

  3. HDU-1272 小希的迷宫 (并查集、判断图是否为树)

    Description 上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardon来走.但是她设计迷宫的思路不一样,首先她认为所有的通道都应该是双向连通的,就 ...

  4. 【HDU1272】小希的迷宫(并查集基础题)

    仍旧裸敲并查集.有这两点注意: 1.输入 0 0 时候要输出YES 2.留心数组的初始化 #include <iostream> #include <cstring> #inc ...

  5. HDU1272:小希的迷宫(并查集)

    小希的迷宫 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  6. HDU 1272 小希的迷宫 (并查集)

    小希的迷宫 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/L Description 我们的小伙伴Bingo身为大二学长,他乐于 ...

  7. HDU 1272 小希的迷宫(并查集) 分类: 并查集 2015-07-07 23:38 2人阅读 评论(0) 收藏

    Description 上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardon来走.但是她设计迷宫的思路不一样,首先她认为所有的通道都应该是双向连通的,就 ...

  8. ACM学习历程—HDU 1272 小希的迷宫(并查集)

    Description 上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardon来走.但是她设计迷宫的思路不一样,首先她认为所有的通道都应该是双向连通的,就 ...

  9. HDU——1272小希的迷宫(并查集+拓扑排序)

    小希的迷宫 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  10. HDU 1272: 小希的迷宫(并查集)

    小希的迷宫 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

随机推荐

  1. Unity3D 绘制扇形/环形

    using UnityEngine; using System.Collections; using System.Collections.Generic; public class Cone : M ...

  2. [暑假集训--数论]poj2909 Goldbach's Conjecture

    For any even number n greater than or equal to 4, there exists at least one pair of prime numbers p1 ...

  3. poj 2441 Arrange the Bulls

    Arrange the Bulls Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 5427   Accepted: 2069 ...

  4. jquery取得iframe中元素的方法

    原文发布时间为:2010-12-27 -- 来源于本人的百度文章 [由搬家工具导入] 收集利用Jquery取得iframe中元素的几种方法 :contents()  $.trim($("if ...

  5. linux下不是很完美的提高android虚拟机的启动速度

    去年双十一换的新电脑,华硕vivo4000的,配置的不算很好,4k的屏幕:3840×2160, 940M的显卡, core i7的CPU, 8G的内存,硬盘是1T的机械硬盘,除了硬盘基本感觉还可以吧. ...

  6. linux根文件系统制作之busybox编译和系统构建【转】

    转自:http://blog.chinaunix.net/uid-29401328-id-5019660.html 介绍完相关文件后我们开始构建文件系统,涉及到的文件等到具体用到的时候再讲. 一.编译 ...

  7. linux 常用命令: runuser

    rpm: coreutils-8.4-9.el6.x86_64 runuser --help 用法:runuser [选项]... [-] [用户 [参数]... ] Change the effec ...

  8. TreeMap和TreeSet的区别与联系

    TreeMap 和 TreeSet 是 Java Collection Framework 的两个重要成员,其中 TreeMap 是 Map 接口的常用实现类,而 TreeSet 是 Set 接口的常 ...

  9. Guice 4.1教程

    Guice是Google开发的一个开源轻量级的依赖注入框架,运行速度快,使用简单. 项目地址:https://github.com/google/guice/ 最新的版本是4.1,本文基于此版本. 0 ...

  10. react 使用antd导航组件实现事件传递并局部刷新DOM

    我们要实现一个通过点击顶部导航来查询左侧菜单的一个功能 在这个功能中,我们要应用到onClick={this.headNavMenuList.bind(this)}方法来传递点击 不同按钮来传递不同的 ...