Gym 101334C 无向仙人掌


给出图,求他的“仙人掌度”,即求包括他自身的生成子图有多少?
只能删去仙人掌上的叶子的一条边,然后根据乘法原理相乘;
1、怎么求一个仙人掌叶子上有多少边? 可以利用点,边双连通的时间戳这个概念,但是绝对时间是不对的,只能用相对的时间戳。
2、怎么把第二种情况剔除掉? 就是记录每一个点加入环中的次数;
3、第三种情况,就是判连通了;
#include <bits/stdc++.h>
using namespace std;
const int maxn = + ;
struct Sol {
vector<int> G[maxn];
int cyclecnt;
int cycle[maxn];
int dfn[maxn];
int c[maxn];
int n;
int num[maxn];
void init(int n) {
this->n = n;
for(int i=; i<=n; i++)
G[i].clear();
memset(dfn,,sizeof(dfn));
memset(cycle,,sizeof(cycle));
memset(num,,sizeof(num));
cyclecnt = ;
dfn[] = ;
}
void AddEdge (int from,int to) {
G[from].push_back(to);
G[to].push_back(from);
}
void dfs(int u,int fa) {
for(int i=; i<G[u].size(); i++) {
int v = G[u][i];
if(v==fa) continue;
if(!dfn[v]) {
dfn[v] = dfn[u] + ;
dfs(v,u);
c[u]+=c[v];
} else if(dfn[v]<dfn[u]) {
cycle[cyclecnt++] = dfn[u] - dfn[v] + ;
c[u]++;
c[v]--;
}
}
}
void ans() {
for(int i=; i<=n; i++)
if(c[i]>||dfn[i]==) {
puts("");
return;
}
//int res = 1;
//for(int i=0;i<cyclecnt;i++)
// res = res * cycle[i];
//return res;
int len = ;
num[] = ;
for(int i=; i<cyclecnt; i++) {
for(int j=; j<=len; j++)
num[j] = num[j]*cycle[i];
for(int j=; j<=len; j++) {
num[j+] += num[j]/;
num[j] = num[j]%;
}
while(num[len+]) {
num[len+]+=num[len+]/;
num[++len]%=;
}
}
for(int i=len; i>=; i--)
printf("%d",num[i]);
puts("");
}
} sol;
int main() {
freopen("cactus.in","r",stdin);
freopen("cactus.out","w",stdout);
int n,m;
scanf("%d%d",&n,&m);
sol.init(n);
for(int i=; i<m; i++) {
int k,u;
scanf("%d%d",&k,&u);
for(int i=; i<k-; i++) {
int v;
scanf("%d",&v);
sol.AddEdge(u,v);
u = v;
}
}
sol.dfs(,-);
sol.ans();
//printf("%d\n",sol.ans());
return ;
}
Gym 101334C 无向仙人掌的更多相关文章
- HDU 6041.I Curse Myself 无向仙人掌图
I Curse Myself Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- Gym - 101334C 3514 无向仙人掌
http://codeforces.com/gym/101334/attachments 题意: 判断是否是仙人掌图并且连通,如果是的话则计算出它有多少个连通子图也是仙人掌. 思路:连通子图也就是我们 ...
- $dy$讲课总结
字符串: 1.广义后缀自动机(大小为\(m\))上跑一个长度为\(n\)的串,所有匹配位置及在\(parent\)树上其祖先的数量的和为\(min(n^2,m)\),单次最劣是\(O(m)\). 但是 ...
- codeforces GYM 100114 J. Computer Network 无相图缩点+树的直径
题目链接: http://codeforces.com/gym/100114 Description The computer network of “Plunder & Flee Inc.” ...
- Gym 100553B Burrito King 无脑背包
题意就是你有n和m两个上限 吃一个东西会同时增加两个东西 m的值不能超过给定的m 问最后的n m值和每个东西吃了多少 贪心一下就好了 算一下性价比 从最大的开始吃 直到吃满了m n也一定是最大了 只是 ...
- 深度|OpenAI 首批研究成果聚焦无监督学习,生成模型如何高效的理解世界(附论文)
本文经机器之心(微信公众号:almosthuman2014)授权转载,禁止二次转载,原文. 选自 Open AI 作者:ANDREJ KARPATHY, PIETER ABBEEL, GREG BRO ...
- 【BZOJ-1952】城市规划 [坑题] 仙人掌DP + 最大点权独立集(改)
1952: [Sdoi2010]城市规划 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 73 Solved: 23[Submit][Status][ ...
- 【BZOJ-4316】小C的独立集 仙人掌DP + 最大独立集
4316: 小C的独立集 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 57 Solved: 41[Submit][Status][Discuss] ...
- (转)【重磅】无监督学习生成式对抗网络突破,OpenAI 5大项目落地
[重磅]无监督学习生成式对抗网络突破,OpenAI 5大项目落地 [新智元导读]"生成对抗网络是切片面包发明以来最令人激动的事情!"LeCun前不久在Quroa答问时毫不加掩饰对生 ...
随机推荐
- Ionic3,懒加载(二)
Ionic懒加载: 普通的ionic项目中,创建好每一个Component页面后,都需要在app.module.ts中进行declaration(声明)后才能进行调用,而这样的声明方式,及在APP加载 ...
- (转) Linux Shell经典实例解析
原文:http://blog.csdn.net/yonggeit/article/details/72779955 该篇博客作为对之前Linux Shell常用技巧和高级技巧系列博客的总结,将以Ora ...
- 动态替换animator的研究
http://blog.csdn.net/tonnychu/article/details/49903657 http://blog.csdn.net/tlrainty/article/details ...
- Coursera 机器学习 第9章(下) Recommender Systems 学习笔记
9.5 Predicting Movie Ratings9.5.1 Problem Formulation推荐系统.推荐系统的问题表述:电影推荐.根据用户对已看过电影的打分来推测用户对其未打分的电影将 ...
- document.write与document.getElementById.innterHTML的区别
<html> <head> <meta charset="utf-8"> <script> var tmp = "< ...
- Enjoy coding
Enjoy coding iTerm配置 主题选择 Solarized Dark LiquidCarbon 字体选择 Cousine for Powerline(需要安装Powerline字体库), ...
- [shell基础]——echo命令
echo命令:在shell中主要用于输出 1. -n 不换行的显示结果(默认是换行的) 2. -e " " 支持双引号中使用一些特殊字符 常用的特殊字符有 \a 发出警告 ...
- AtCoder Grand Contest 023 F - 01 on Tree
Description 题面 Solution HNOI-day2-t2 复制上去,删点东西,即可 \(AC\) #include<bits/stdc++.h> using namespa ...
- 项目搭建系列之二:SpringMVC框架下配置MyBatis
1.什么是MyBatis? MyBatis是一个支持普通SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis消除了几乎所有的JDBC代码和参数的手工设置以及对结果集的检索封装.MyBatis ...
- Unity3D第二课之通过键盘、鼠标移动物体
public class xuanzhuan : MonoBehaviour { //平移速度变量 public float MoveSpeed;// Use this for initializat ...