当前位置:网站首页>HNOI2012矿场搭建
HNOI2012矿场搭建
2022-07-26 00:12:00 【lovesickman】
HNOI2012矿场搭建
题意
给定一个无向图,可能不连通,如果图中某个点坍塌,要求其他点一定能从某个出口逃出,问:至少设计几个出口和不同的最小救援出口的设置数量。
貌似发现了蓝书上(P404)求low数组的错误(雾)
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
const int N=510*2,M=1010;
int n,m,h[N],ne[M],e[M],idx;
int dfn[N],low[N],tim;
int stack[N],top;
vector<int>dcc[N];
int dcc_cnt,root;
bool cut[N];
void add(int a,int b)
{
e[idx]=b,ne[idx]=h[a],h[a]=idx++;
}
void tarjan(int x)
{
low[x]=dfn[x]=++tim;
stack[++top]=x;
if(x==root&&h[x]==-1)
{
dcc[++dcc_cnt].push_back(x);
return ;
}
int cnt=0;
for(int i=h[x];~i;i=ne[i])
{
int j=e[i];
if(!dfn[j])
{
tarjan(j);
low[x]=min(low[x],low[j]);
if(dfn[x]<=low[j])
{
cnt++;
if(x!=root||cnt>1)
cut[x]=true;
int y;
dcc_cnt++;
do{
y=stack[top--];
dcc[dcc_cnt].push_back(y);
}while(y!=j);
dcc[dcc_cnt].push_back(x);
}
}
else low[x]=min(low[x],dfn[j]);
}
}
int main()
{
int t=1;
while(cin>>m,m)
{
for(int i=1;i<=dcc_cnt;i++)
dcc[i].clear();
idx=tim=top=dcc_cnt=n=0;
memset(h,-1,sizeof h);
memset(dfn,0,sizeof dfn);
memset(cut,0,sizeof cut);
while(m--)
{
int a,b;cin>>a>>b;
add(a,b),add(b,a);
n=max(n,a),n=max(n,b);
}
for(root=1;root<=n;root++)
if(!dfn[root])
tarjan(root);
int res=0;
unsigned long long num=1;
cout<<dcc_cnt<<endl;
cout<<"---"<<endl;
for(int i=1;i<=n;i++)
cout<<i<<" "<<dfn[i]<<" "<<low[i]<<endl;
cout<<endl;
for(int i=1;i<=dcc_cnt;i++)
{
int cnt=0;
for(int j=0;j<dcc[i].size();j++)
{
if(cut[dcc[i][j]])
cnt++;
}
if(cnt==0)
{
if(dcc[i].size()>1)
res+=2,num*=dcc[i].size()*(dcc[i].size()-1)/2;
else
res++;
}
else if(cnt==1)
res++,num*=dcc[i].size()-1;
cout<<"cnt="<<cnt<<endl;
}
printf("Case %d: %d ",t++,res);
cout<<num<<endl;
cout<<top<<" "<<stack[top]<<endl;
}
return 0;
}
边栏推荐
- This time, thoroughly understand promise principle
- 牛血清蛋白修饰酚酸类及生物碱类小分子/偶联微球的蛋白/牛红细胞SOD的研究
- MySQL - master-slave replication
- LeetCode_ 55_ Jumping game
- Nodejs学习资源
- 链表相关方法
- "Animal coin" is fierce, trap or opportunity? 2021-05-12
- [paper notes] - target attitude estimation Epro PNP 2022 CVPR
- 测试7年,面试华为最后面议要薪1万,HR说我不尊重华为,他们没有那么低薪资的岗位~
- 基于网络分析和文本挖掘的意见领袖影响力研究
猜你喜欢

Installation and configuration of VMware esxi7.0

【Redis】① Redis 的介绍、Redis 的安装

栈的表示和实现(C语言)

Study on bovine serum protein modified phenolic acids and alkaloids small molecules / coupled microspheres protein / bovine erythrocyte SOD
![[英雄星球七月集训LeetCode解题日报] 第25日 树状数组](/img/e6/a59a1719c4381772ce7475d59d5068.png)
[英雄星球七月集训LeetCode解题日报] 第25日 树状数组

Find and locate commands

Preparation of bovine serum albumin modified by low molecular weight protamine lmwp/peg-1900 on the surface of albumin nanoparticles

Opencv learning Day6

寻找命令find和locate

letfaw
随机推荐
Understanding of "dof: a demand oriented framework for imagedenoising"
链表相关方法
【目录】Nodejs、npm、yarn、BUG
Jd.com searches for product API instructions by keyword
Binary tree related knowledge
Yes, UDP protocol can also be used to request DNS server
对比7种分布式事务方案,还是偏爱阿里开源的Seata(原理+实战)
mysql事务的引入
Flask发送验证码逻辑
拼多多根据ID取商品详情 API 的使用说明
Introduction of MySQL transactions
Redis夺命十二问,你能扛到第几问?
白蛋白纳米-超声微泡载组织型纤溶酶原激活物基因靶向制备研究
How to make your JS code more beautiful
[redis] ③ data elimination strategy, pipeline command, publish and subscribe
Understanding of "dbdnet: a deep boosting strategy for imagedenoising"
MWEC:一种基于多语义词向量的中文新词发现方法
[directory] nodejs, NPM, yarn, bug
Nest. JS uses express but not completely
Sliding window_

