当前位置:网站首页>Hnoi2012 mine construction
Hnoi2012 mine construction
2022-07-26 00:35:00 【lovesickman】
HNOI2012 Mine construction
The question
Given an undirected graph , Maybe not connected , If a point in the figure collapses , Other points must be able to escape from an exit , ask : At least design several exits and different minimum rescue exits .
Looks like I found it on the blue book (P404) seek low Array error ( Fog )
#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;
}
边栏推荐
- Pikachu target clearance and source code analysis
- @RequestParam,@PathVariable两个注解的区别
- DC-6 -- vulnhub range
- Private cloud disk setup
- Distributed transactions: the final consistency scheme of reliable messages
- 8个小妙招-数据库性能优化,yyds~
- Verilog grammar basics HDL bits training 06
- [contents] mqtt, nodejs projects
- Binary representation -- power of 2
- Study on bovine serum protein modified phenolic acids and alkaloids small molecules / coupled microspheres protein / bovine erythrocyte SOD
猜你喜欢

MySQL - master-slave replication

基于网络分析和文本挖掘的意见领袖影响力研究

Research on the influence of opinion leaders based on network analysis and text mining

Hcip - republish

Semaphore

Study on bovine serum protein modified phenolic acids and alkaloids small molecules / coupled microspheres protein / bovine erythrocyte SOD

12. Neural network model

SQL server failed to send mail, prompting that the recipient must be specified
![[redis] ② redis general command; Why is redis so fast?; Redis data type](/img/72/aaa90d5411b8b20b15a7f87b98bd27.png)
[redis] ② redis general command; Why is redis so fast?; Redis data type

Verilog语法基础HDL Bits训练 06
随机推荐
前缀异或和,异或差分数组
Understanding of "dbdnet: a deep boosting strategy for imagedenoising"
Tarjan 求强连通分量 O(n+m) ,缩点
【目录】mqtt、nodejs项目
How to open the Internet and ask friends to play together?
Distributed transactions: the final consistency scheme of reliable messages
8个小妙招调整数据库性能优化,yyds
Verilog grammar basics HDL bits training 06
Verilog grammar basics HDL bits training 05
Find the single dog (Li Kou 260)
PC website realizes wechat code scanning login function (II)
【oops-framework】随机数生成管理
Semaphore
Nodejs starts mqtt service with an error schemaerror: expected 'schema' to be an object or Boolean problem solving
2022/7/24 考试总结
Leetcode 笔记 121. 买卖股票的最佳时机
攻防世界web题-favorit_number
MySQL - master-slave replication
寻找命令find和locate
什么是 Web3 游戏?

