网上的题解大都模糊,我可能写的也比较模糊吧,讲究看看。

大致题意:

  原图没有一个割点时,特殊考虑,至少ans1=2个通风井,方案数n*(n-1)/2;

原图上有多个割点时,每个(由割点限制成几部分的)联通块个数即为ans1;需要dfs进行vis标记和iscut区分,不重不漏;

ans2,建设时避开在割点上建设通风井(通风井数量可最小化,以免通风井损毁后还需再建一个以备万一);求解时:当一个颜色块有两个割点时,摧毁一个蚂蚁们总可以通过另一个割点紧急转移;当一个颜色块有仅一个割点时,摧毁割点后就必须在颜色块内部建设一个。

  //五点双环一割点,(发现这个样例:颜色块为1割点不为1,用颜色块来计算就不对头了!)

  12

  5  6  0  1  1  2  0  2  2   3   2  4   3   4

AC题解:

//头文件都私奔了!
#include<set>
using namespace std;
#define N 10100
#define inf 0x3f3f3f3f
typedef unsigned long long ULL;
int n,m,Time; //单指向边的共m条;
vector<int>G[N]; ///一次存贮1个内存!!
int dfn[N],low[N];
int color_num,in[N];
stack<int>st;
int father[N];
int cas;
int color[N]; ///表示i在的颜色块的编号,本题无用!
bool iscut[N]; ///表示i 是否为割点
bool vis[N]; ///dfs中有用
int test_num; ///dfs中从某u点(非割点)出发可以遇见的
set<int>ss; ///从某u点(非割点)出发dfs中的遇见割点(方便去重用set)
ULL mod;///模数 void init()
{
for(int i=;i<=n;i++){
G[i].clear();
}
memset(dfn,,sizeof(dfn));
memset(low,,sizeof(low));
Time=;
color_num=;
memset(in,,sizeof(in));memset(color,,sizeof(color));
memset(iscut,false,sizeof(iscut));
memset(father,-,sizeof(father));
while(!st.empty())st.pop();
}
void tarjan(int u,int fa)
{
dfn[u]=low[u]=++Time;
st.push(u);in[u]=;
father[u]=fa; ///别忘记!
for(int i=;i<(int)G[u].size();i++){
int v=G[u][i];
if(!dfn[v]){
tarjan(v,u);
low[u]=min(low[u],low[v]);
}
else if(v!=fa&&in[u]==){ ///子节点在队列中并且不是父节点
low[u]=min(low[u],dfn[v]);
}
}
if(dfn[u]==low[u]){
++color_num;
int top;
do{
top=st.top();st.pop();
in[top]=;
color[top]=color_num; //细节!
}while(top!=u);
}
}
ULL fact_mod(ULL x){ ///对2的64次方取模(mod只有一半) while(x/(ULL)>=mod)
x=x-mod-mod;
return x;
}
void dfs(int u)
{
vis[u]=;
test_num++; ///从u点出发的由割点分隔开的联通图中的非割点数目
for(int i=;i<(int)G[u].size();i++){
int v=G[u][i];
if(iscut[v]){
ss.insert(v);continue;
}
if(iscut[v]||vis[v])continue; ///vis防重复,iscut防dfs到切点
dfs(v);
}
} void solve() //缩点
{
tarjan(,-); ///单源点图,求DAG
int ans1=;
ULL ans2=;
int rootsons=,u,cnt=; ///cnt表示割点个数
for(int i=;i<n;i++){ ///求割点,分类特判源点0是否为割点
if(father[i]==)
rootsons++;
else{
u=father[i]; ///父节点
if(dfn[u]<=low[i]&&iscut[u]==false){
iscut[u]=true;cnt++;
}
}
}
if(rootsons>){ ///特判源点
iscut[]=true;cnt++;
}
if(cnt==){ ///没有割点的图
ans1=;
ans2=(ULL)n*(n-)/;
ans2=fact_mod(ans2);
}
else{
memset(vis,false,sizeof(vis));
for(int i=;i<n;i++){ ///多个割点的图
if(iscut[i]||vis[i])
continue;
ss.clear();test_num=;
dfs(i);
if(ss.size()<=){
ans1++;ans2=ans2*(ULL)test_num;
}
}
}
ans2=fact_mod(ans2);
printf("Case %d: %d %llu\n",++cas,ans1,ans2);
}
int main()
{
int T;
scanf("%d",&T);
cas=;
mod=(ULL); ///求模数
for(int i=;i<=;i++){
mod=mod*(ULL);
} while(T--){
scanf("%d%d",&n,&m);
init();
int x,y;
for(int i=;i<=m;i++){
scanf("%d%d",&x,&y);
G[x].push_back(y);
G[y].push_back(x);
}
solve();
}
return ;
}

LOJ-1308-Ant network(蚂蚁的网络)-求割点分隔开的子图个数及乘积的更多相关文章

  1. poj 1144 Network【双连通分量求割点总数】

    Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11042   Accepted: 5100 Descript ...

  2. B - Network - uva 315(求割点)

    题意:给一个无向连通图,求出割点的数量. 首先输入一个N(多实例,0结束),下面有不超过N行的数,每行的第一个数字代表后面的都和它存在边,0表示行输入的结束(很蛋疼的输入方式). 分析:割点的模板题 ...

  3. Network UVA - 315(求割点)

    #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> ...

  4. POJ 1144 Network(Tarjan求割点)

    Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12707   Accepted: 5835 Descript ...

  5. uva 315 Network(无向图求割点)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  6. NFS - Network File System网络文件系统

    NFS(Network File System/网络文件系统): 设置Linux系统之间的文件共享(Linux与Windows中间文件共享采用SAMBA服务): NFS只是一种文件系统,本身没有传输功 ...

  7. POJ 1144 Network(tarjan 求割点个数)

    Network Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17016   Accepted: 7635 Descript ...

  8. poj 1144 Network 无向图求割点

    Network Description A Telephone Line Company (TLC) is establishing a new telephone cable network. Th ...

  9. UVA315:Network(求割点)

    Network 题目链接:https://vjudge.net/problem/UVA-315 Description: A Telephone Line Company (TLC) is estab ...

随机推荐

  1. git 获取线上代码并合并到本地

    //查询当前远程的版本 $ git remote -v //获取最新代码到本地(本地当前分支为[branch],获取的远端的分支为[origin/branch]) $ git fetch origin ...

  2. mysql函数concat与group_concat使用说明

    mysql函数concat与group_concat使用说明concat()函数<pre>mysql> select concat(',',name,',') from `user` ...

  3. 使用IDEA打开工程未显示左侧工程目录栏

    1. 重启IDEA2. 删除要打开的项目文件夹下的.idea文件夹3. open打开项目即可 注意: 是重启IDEA,不是只关闭IDEA的单个窗口 参考: https://blog.csdn.net/ ...

  4. hdoj4099(字典树+高精度)

    题目链接:https://vjudge.net/problem/HDU-4099 题意:给T组询问,每个询问为一个字符串(长度<=40),求以该字符串为开始的fibonacci数列的第一个元素的 ...

  5. Jenkins在Mac上的安装与维护

    卸载 开篇提前说下, 因为很久之前用安装包装过的, 我要先卸载: /Library/Application\ Support/Jenkins/Uninstall.command 注意:如果没有权限的话 ...

  6. Redis 缓存问题及解决方案

    [相关概念] 缓存击穿:指的是一些热点数据过期,由于热点数据存在并发量大的特性,所以短时间内对数据库的造成很大的冲击,导致系统瘫痪.常见于例如微博系统中明星结婚或出轨时微博瘫痪的情况. 缓存雪崩:指的 ...

  7. Prometheus入门到放弃(2)之Node_export安装部署

    1.下载安装 node_exporter服务需要在三台机器都安装,这里我们以一台机器为例: 地址:https://prometheus.io/download/ ### 另外两个节点部署时,需要先创建 ...

  8. 记一次SQL优化

    常见的SQL优化 一.查询优化 1.避免全表扫描 模糊查询前后加%也属于全表扫描 在where子句中对字段进行表达式操作会导致引擎放弃使用索引而进行全表扫描,如: select id from t w ...

  9. 使用Lombok总结

    Lombok学习总结 Project Lombok is a java library that automatically plugs into your editor and build tool ...

  10. PyCharm:设置py文件头部信息

    P PyCharm:设置py文件头部信息file->setting->appearance & behavior->editor->file and code temp ...