当前位置:网站首页>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;
}
边栏推荐
- [redis] ② redis general command; Why is redis so fast?; Redis data type
- VMware ESXI7.0版本的安装与配置
- FreeRTOS个人笔记-互斥量
- Preparation of bovine erythrocyte superoxide dismutase sod/ folic acid coupled 2-ME albumin nanoparticles modified by bovine serum albumin
- Appium中控件元素封装类梳理
- "Animal coin" is fierce, trap or opportunity? 2021-05-12
- 34 use of sparksql custom functions, architecture and calculation process of sparkstreaming, dstream conversion operation, and processing of sparkstreaming docking Kafka and offset
- 寻找命令find和locate
- 【redis】③ 数据淘汰策略、pipeline 管道命令、发布订阅
- Pikachu靶机通关和源码分析
猜你喜欢

After using MQ message oriented middleware, I began to regret

【redis】③ 数据淘汰策略、pipeline 管道命令、发布订阅

软件测试同行评审到底是什么?

MPLS实验

letfaw

J9 number theory: what is Dao mode? Obstacles to the development of Dao

What does it mean that the web server stops responding?

测试7年,面试华为最后面议要薪1万,HR说我不尊重华为,他们没有那么低薪资的岗位~

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

Redirection and request forwarding
随机推荐
JVM 三色标记法与读写屏障
NVIDIA programmable reasoning accelerator tensorrt learning notes (III) -- Accelerating reasoning
白蛋白纳米-超声微泡载组织型纤溶酶原激活物基因靶向制备研究
Duplicate disk: recommended system - negative sampling strategy
Unified handling of global exceptions
Appium中控件元素封装类梳理
8种MySQL常见SQL错误用法,我全中
matlab实时作出串口输出数据的图像
PC website realizes wechat code scanning login function (II)
letfaw
[hero planet July training leetcode problem solving daily] 25th tree array
MySQL——数据库日志
CountDownLatch
Detailed explanation of C language preprocessing
寻找命令find和locate
Solid smart contract development - 3.2-solid syntax array, structure, mapping
Thymeleaf view integration
软件测试同行评审到底是什么?
【目录】mqtt、nodejs项目
牛血清蛋白修饰酚酸类及生物碱类小分子/偶联微球的蛋白/牛红细胞SOD的研究

