HDU1272 迷宫通路数

#include <iostream>
#include<stdio.h>
#include<cstring> using namespace std;
#define MAXN 100100
int fa[MAXN];
int sign[MAXN];
int flag; int getHead(int a)
{
while(a!=fa[a]) a=fa[a];
return a;
} void uni(int x,int y)
{
int fa_x=getHead(x);
int fa_y=getHead(y);
if(fa_x==fa_y) flag=;
else fa[fa_x]=fa_y;
} int main()
{
int A,B;
while(){
memset(fa,,sizeof(fa));
memset(sign,,sizeof(sign));
scanf("%d%d",&A,&B);
if(A==-&&B==-) break;
if(A==&&B==) {
printf("Yes\n\n");
continue;
} fa[A]=A,fa[B]=A;
sign[A]=,sign[B]=; flag=;
while(scanf("%d%d",&A,&B)&&A!=&&B!=){
if(!sign[A]) sign[A]=,fa[A]=A;
if(!sign[B]) sign[B]=,fa[B]=B;
uni(A,B);
} int k=;
for(int i=;i<MAXN;i++)
if(sign[i]&&fa[i]==i) k++;
if(k>) flag=;
if(flag==) printf("No\n\n");
else printf("Yes\n\n");
} return ;
}
HDU1272 迷宫通路数的更多相关文章
- 插头DP专题
建议入门的人先看cd琦的<基于连通性状态压缩的动态规划问题>.事半功倍. 插头DP其实是比较久以前听说的一个东西,当初是水了几道水题,最近打算温习一下,顺便看下能否入门之类. 插头DP建议 ...
- 【java并发核心一】Semaphore 的使用思路
最近在看一本书<Java并发编程 核心方法与框架>,打算一边学习一边把学习的经验记下来,所粘贴的代码都是我运行过的,大家一起学习,欢迎吐槽. 估计也没多少人看我的博客,哈哈,那么我还是会记 ...
- HDU 2157 How many ways?? 【矩阵经典8】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=2157 How many ways?? Time Limit: 2000/1000 MS (Java/Ot ...
- HDU 2243 考研路茫茫——单词情结 求长度小于等于L的通路总数的方法
http://acm.hdu.edu.cn/showproblem.php?pid=2243 这是一题AC自动机 + 矩阵快速幂的题目, 首先知道总答案应该是26^1 + 26^2 + 26^3 .. ...
- Day4 - K - Ant Trip HDU - 3018
Ant Country consist of N towns.There are M roads connecting the towns. Ant Tony,together with his fr ...
- JAVA 算法练习(二)
和上次一样,虽说用 java 语言,但有 c 的基础一样可以看懂哦. 机器人走方格问题Ⅰ 题目概述 有一个XxY的网格,一个机器人只能走格点且只能向右或向下走,要从左上角走到右下角.请设计一个算法,计 ...
- 1003 Emergency (25分)
As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...
- Semaphore 的使用思路
转自:https://www.cnblogs.com/klbc/p/9500947.html 最近在看一本书<Java并发编程 核心方法与框架>,打算一边学习一边把学习的经验记下来,所粘贴 ...
- hdu1272 小希的迷宫
Problem Description 上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardon来走.但是她设计迷宫的思路不一样,首先她认为所有的通道都应该 ...
随机推荐
- RHEL 6.5----Varnish缓存服务器
主机名 IP 服务 master 192.168.30.130 varnish slave 192.168.30.131 httpd WebServer 192.168.30.1 ...
- select选择框中,model传的值并非是页面上的值,而是另一个值
对于编程来说,money和rebate代表的是金额优惠和折扣优惠,采用money或rebate便于数据存储.但是页面显示给用户的时候是金额优惠和折扣优惠,并不是显示编程中所存储数据.所以选择的mode ...
- poj3616 Milking Time
思路: dp. 实现: #include <iostream> #include <cstdio> #include <algorithm> using names ...
- poj3280 Cheapest Palindrome
思路: 区间dp.添加和删除本质相同. 实现: #include <iostream> #include <cstdio> using namespace std; int n ...
- [BZOJ2761][JLOI2011]不重复数字 暴力
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2761 直接暴力. #include<cstdio> #include<c ...
- ES6学习笔记(10)----Set和Map数据结构
参考书<ECMAScript 6入门>http://es6.ruanyifeng.com/ Set和Map数据结构 1.Set 基本用法 Set是一种新的数据结构,它的成员都是唯一 ...
- iOS 随笔小技巧 弱self 打印当前类行数列数,多人开发自动适配pch地址,获取设备uid的信息
$(SRCROOT)/PrefixHeader.pch自动适配pch地址 __weak __block typeof(self) weakself = self; __weak typeof(self ...
- java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()
原因:hibernate-jpa-2.0-api-1.0.0.Final.jar.ejb3-persistence.jar中的javax.persistence与javaEE 5 Librares中的 ...
- mac下elasticsearch安装部署
下载elaticsearch集成包 优势:封装了对插件的支持,且安装方式较简单 地址:https://github.com/medcl/elasticsearch-rtf 解压到指定目录后,获取该集成 ...
- IOS文件下载
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, ...