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个询问,每个询问两个点,问这两个点之间有多少条简单路. 挺综 ...
随机推荐
- 牛客网Java刷题知识点之Iterator和ListIterator的区别
不多说,直接上干货! https://www.nowcoder.com/ta/review-java/review?query=&asc=true&order=&page=21 ...
- 開玩樹莓派(二):配置IP,實現無顯示器局域網內Putty連接和RDP遠程
目錄: 開玩樹莓派(一):安裝Raspbian系統 開玩樹莓派(二):配置IP,實現無顯示器局域網內Putty連接和RDP遠程 開玩樹莓派(三):Python編程 開玩樹莓派(四):GPIO控制和遠程 ...
- [问题记录]Ubuntu下chmsee安装失败的解决
日期:2016年2月26日 一直在找Ubuntu下查看chm的工具但是普遍不理想,发现在deepin中的chmsee相对比较好,但是直接执行网上的sudo apt-get install chmsee ...
- JavaScript 30 - 3 学习笔记
今天学习的是JavaScript 30-3 ---css Variables 实现的效果如下图所示. 废话不多,我们直接来看代码. html: <h1>大家好,这个一个<span c ...
- Json字符串转excel表格文件
假如我们有一段json串,该json串是由一系列结构相同的数据集合组成,如下: { "data": [ { "groupId": "com.test. ...
- No input file specified的解决方法
(一)IIS Noinput file specified 方法一:改PHP.ini中的doc_root行,打开ini文件注释掉此行,然后重启IIS 方法二:请修改php.ini找到; cgi.for ...
- Java静态方法不能被覆盖
// 静态方法不能被覆盖 /*class Super{ static String name(){ return "mother"; } } ...
- 【Web应用-Web作业】Web 作业无法直接运行 jar 文件
问题描述 在经典管理门户中将直接压缩的 jar 文件打包为 zip 包,上传到 web 作业时报错. 解决方法 jar 文件的运行需要依托于 java 进程,所以在运行 jar 文件时,我们都会以格式 ...
- IDEA 启用/禁用 Run Dashboard
一.启用 方式一: 创建/打开一个SpringBoot项目[或者点击Run --> Edit Configurations 添加 Spring Boot 类型的项目配置:或者如图在红框处添加配置 ...
- HDU 4291 A Short problem 短问题 (递推,找规律)
题意: 给出递推式 g(n) = 3g(n - 1) + g(n - 2),且g(1) = 1,g(0) = 0.求g( g( g(n))) mod 109 + 7. 思路: 要求的g( g( g(n ...