hdu3594 Cactus
仙人掌入门简单题。
先看一篇文档。
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int T, n, uu, vv, hea[20005], cnt, dfn[20005], loo[20005], idx, vis[20005];
bool isok;
struct Edge{
int too, nxt;
}edge[50005];
void add_edge(int fro, int too){
edge[++cnt].nxt = hea[fro];
edge[cnt].too = too;
hea[fro] = cnt;
}
void dfs(int x){
if(!isok) return ;
dfn[x] = loo[x] = ++idx;
vis[x] = 1;
int num=0;
for(int i=hea[x]; i; i=edge[i].nxt){
int t=edge[i].too;
if(vis[t]==2) isok = false;//1
else if(!vis[t]){
dfs(t);
if(loo[t]>dfn[x]) isok = false;//2
if(loo[t]<dfn[x]){//3
num++;
loo[x] = min(loo[x], loo[t]);
}
}
else{//3
loo[x] = min(loo[x], dfn[t]);
num++;
}
}
vis[x] = 2;
if(num>1) isok = false;
}
int main(){
cin>>T;
while(T--){
scanf("%d", &n);
memset(dfn, 0, sizeof(dfn));
memset(loo, 0, sizeof(loo));
memset(hea, 0, sizeof(hea));
memset(vis, 0, sizeof(vis));
isok = true;
cnt = idx = 0;
while(scanf("%d %d", &uu, &vv)!=EOF){
if(!uu && !vv) break;
add_edge(uu+1, vv+1);
}
dfs(1);
if(idx<n) isok = false;
printf(isok?"YES\n":"NO\n");
}
return 0;
}
hdu3594 Cactus的更多相关文章
- 判断强联通图中每条边是否只在一个环上(hdu3594)
hdu3594 Cactus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- Codeforces Round #143 (Div. 2) E. Cactus 无向图缩环+LCA
E. Cactus A connected undirected graph is called a vertex cactus, if each vertex of this graph bel ...
- 仙人掌(cactus)
仙人掌(cactus) Time Limit:1000ms Memory Limit:64MB 题目描述 LYK 在冲刺清华集训(THUSC) !于是它开始研究仙人掌,它想来和你一起分享它最近研究的 ...
- 【BZOJ】【1023】【SHOI2008】cactus仙人掌图
DP+单调队列/仙人掌 题解:http://hzwer.com/4645.html->http://z55250825.blog.163.com/blog/static/150230809201 ...
- 1023: [SHOI2008]cactus仙人掌图 - BZOJ
Description如果某个无向连通图的任意一条边至多只出现在一条简单回路(simple cycle)里,我们就称这张图为仙人图(cactus).所谓简单回路就是指在图上不重复经过任何一个顶点的回路 ...
- Cactus入门
这是一个WebProject,有关Cactus用法详见本文测试用例 首先是web.xml <?xml version="1.0" encoding="UTF-8&q ...
- Cactus借助Jetty测试Servlet
这是一个WebProject,但不需要web.xml,因为用不到它 首先是待测试的LoginServlet.java package com.jadyer.servlet; import java.i ...
- bzoj 1023: [SHOI2008]cactus仙人掌图 tarjan缩环&&环上单调队列
1023: [SHOI2008]cactus仙人掌图 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 1141 Solved: 435[Submit][ ...
- Codeforces 231E - Cactus
231E - Cactus 给一个10^5个点的无向图,每个点最多属于一个环,规定两点之间的简单路:从起点到终点,经过的边不重复 给10^5个询问,每个询问两个点,问这两个点之间有多少条简单路. 挺综 ...
随机推荐
- 自己项目中PHP常用工具类大全分享
<?php /** * 助手类 * @author www.shouce.ren * */ class Helper { /** * 判断当前服务器系统 * @return string */ ...
- MySQL数据库报错:Too many connection
每次搭建环境运行一段时间,后台就会报错:com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data sourc ...
- 我的NopCommerce之旅(2): 系统环境及技术分析
一.系统环境 IIS7.0 or above ASP.NET 4.5(MVC 5.0) .NET Framework 4.5.1 or above VS 2012 or above 二.架构设计 Pl ...
- 【转】java的动态代理机制详解
java的动态代理机制详解 在学习Spring的时候,我们知道Spring主要有两大思想,一个是IoC,另一个就是AOP,对于IoC,依赖注入就不用多说了,而对于Spring的核心AOP来说,我们 ...
- CF1072C Cram Time
思路: 首先二分找到使x * (x + 1) / 2 <= a + b最大的x,然后令p = min(a, b), q = max(a, b),按照x,x - 1, ..., 1的顺序选取数字把 ...
- OutOfMemory
查看图片格式,如果为PNG,可更改为jpg.图片会变小. 停止activity 当activity调用onStop()方法, activity不再可见,并且应该释放那些不再需要的所有资源.一旦acti ...
- myeclipse报错MA
以下问题萌新问了我很多次了,无奈写个随笔.之后问的我都在这个随笔里补充. 断电/自动关机导致的问题: Could not open the editor: the file does not exis ...
- struts2默认拦截器defaultStack
第一次使用Struts2.3.20,前台页面向后台传值,怎么总是提示值为null,查找半天原来是struts配置文件的action中忘记引入defaultStack拦截器了,所以即使Action中万事 ...
- idea Please specify commit message
在idea中使用github来进行版本控制的时候, 当点击提交的时候遇到了这个问题 错误: Please specify commit message 解决方法: 在commit message中填写 ...
- Linux内核漏洞利用-环境配置(转)
实验环境: Ubuntu-14.04.1 x86 linux-2.6.32.1 busybox-1.27.2 qemu 0x00 安装qemu sudo apt-get install qemu qe ...