【HDOJ】1325 Is It A Tree?
并查集。需要考虑入度。
#include <stdio.h>
#include <string.h> #define MAXNUM 10005 int bin[MAXNUM];
int degree[MAXNUM];
int nums[MAXNUM]; int find(int x) {
int r = x; while (bin[r] != r)
r = bin[r]; return r;
} int main() {
int x, y, fx, fy, n, case_n = ;
int i, flg; while () {
scanf("%d %d", &x, &y);
if (x< && y<)
break;
memset(degree, , sizeof(degree));
n = ;
++case_n;
if (x== && y==) {
printf("Case %d is a tree.\n", case_n);
continue;
}
for (i=; i<MAXNUM; ++i)
bin[i] = i;
fx = find(x);
fy = find(y);
bin[fy] = fx;
degree[y]++;
flg = ;
nums[n++] = x;
nums[n++] = y;
while () {
scanf("%d %d", &x, &y);
if (x== && y==)
break;
fx = find(x);
fy = find(y);
if (fx != fy) {
bin[fy] = fx;
degree[y]++;
} else {
bin[fy] = fx;
degree[y]++;
flg = ;
}
nums[n++] = x;
nums[n++] = y;
}
fx = find(nums[]);
for (i=; i<n; ++i) {
fy = find(nums[i]);
if (fx != fy) {
flg = ;
break;
}
}
for (i=; i<n; ++i) {
if (degree[nums[i]] > ) {
flg = ;
break;
}
}
if (flg)
printf("Case %d is a tree.\n", case_n);
else
printf("Case %d is not a tree.\n", case_n);
} return ;
}
【HDOJ】1325 Is It A Tree?的更多相关文章
- 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java
[LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...
- 【BZOJ2843】极地旅行社(Link-Cut Tree)
[BZOJ2843]极地旅行社(Link-Cut Tree) 题面 BZOJ 题解 \(LCT\)模板题呀 没什么好说的了.. #include<iostream> #include< ...
- 【BZOJ4530】大融合(Link-Cut Tree)
[BZOJ4530]大融合(Link-Cut Tree) 题面 讨厌权限题!!! Loj链接 题目描述 小强要在 N个孤立的星球上建立起一套通信系统.这套通信系统就是连接 N个点的一个树.这个树的边是 ...
- 【BZOJ1969】航线规划(Link-Cut Tree)
[BZOJ1969]航线规划(Link-Cut Tree) 题面 BZOJ 题解 删边操作 套路呀 离线读入倒过来做 变成加边操作 现在考虑怎么确定两点直接的关键路径条数 如果是一棵树,那么每条边都是 ...
- 【BZOJ4825】【HNOI2017】单旋(Link-Cut Tree)
[BZOJ4825][HNOI2017]单旋(Link-Cut Tree) 题面 题面太长,懒得粘过来 题解 既然题目让你写Spaly 那就肯定不是正解 这道题目,让你求的是最大/最小值的深度 如果有 ...
- 【BZOJ3669】【Noi2014】魔法森林(Link-Cut Tree)
[BZOJ3669][Noi2014]魔法森林(Link-Cut Tree) 题面 题目描述 为了得到书法大家的真传,小 E 同学下定决心去拜访住在魔法森林中的隐 士.魔法森林可以被看成一个包含 n ...
- 【BZOJ2049】洞穴勘测(Link-Cut Tree)
[BZOJ2049]洞穴勘测(Link-Cut Tree) 题面 题目描述 辉辉热衷于洞穴勘测. 某天,他按照地图来到了一片被标记为JSZX的洞穴群地区.经过初步勘测,辉辉发现这片区域由n个洞穴(分别 ...
- 【BZOJ3999】[TJOI2015]旅游(Link-Cut Tree)
[BZOJ3999][TJOI2015]旅游(Link-Cut Tree) 题面 BZOJ 洛谷 题解 一道不难的\(LCT\)题(用树链剖分不是为难自己吗,这种有方向的东西用\(LCT\)不是方便那 ...
- 【BZOJ5212】[ZJOI2018]历史(Link-Cut Tree)
[BZOJ5212][ZJOI2018]历史(Link-Cut Tree) 题面 洛谷 BZOJ 题解 显然实际上就是给定了一棵树和每个点被\(access\)的次数,求解轻重链切换的最大次数. 先考 ...
随机推荐
- Hadoop书籍汇总
<Hadoop实战>陆嘉恒 <Hadoop - The Definitive Guide>Tom White,中文版<Hadoop权威指南> <Hadoop技 ...
- php curl_init函数用法
原文地址:curl_init函数用法">php curl_init函数用法作者:loading 使用PHP的cURL库可以简单和有效地去抓网页.你只需要运行一个脚本,然后分析一下你所抓 ...
- IIS 上发布ASP.NET5
原文 http://docs.asp.net/en/latest/publishing/iis.html 1.安装HTTP Platform Handler ,这个是必需的,不然无法通过IIS访问AS ...
- 如何获得Windows 8中已记住的WIFI的明文密码
网上很流行的一种查看WIFI密码明文的方法,如下: 今天遇到了一种状况,就是如果不连WIFI的情况我能抓到这个密码吗?(实在不想开口问同事密码多少,只能苦逼的自己想办法了o(︶︿︶)o ) 答案当然是 ...
- rest例子
http://www.xdemo.org/spring-restful/(可用) http://www.open-open.com/lib/view/open1389075258125.html(有例 ...
- AUTOTRACE Statistics常用列解释
AUTOTRACE Statistics常用列解释 序号 列名 解释 1 db block gets 从buffer cache中读取的block的数量 2 consistent gets 从buff ...
- 查看xcode的路径
sudo /usr/libexec/locate.updatedb locate liblaunch_sim
- power shell upload file to azure storage
# Azure subscription-specific variables. $storageAccountName = "storage-account-name" $con ...
- php利用时间生成随机函数
date("YmdHis",time()); rand(); 生成随机数 当括号内无参数时 系统会以当前时间为种子进行随机数的生成 rand(1,10); 括号里面是生 ...
- jQuery 源码细读 -- $.Callbacks
$.Callbacks 是 jQuery 提供的可以方便地处理各种回调(callback)列表的类,其源代码是闭包的经典实现. 基本原理就是通过在闭包环境内保存一个 list = [] 数组用于存储回 ...