fzu2181(点的双连通分量+求奇环)
求出每个点双连通分量,如果在一个点双连通分量中有奇环,则这个分量每个点都在一个奇环中。 关键是要知道怎么求点双连通分量以及点双连通的性质。
fzu2181 http://acm.fzu.edu.cn/problem.php?pid=2181
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define N 1100 int n,m,k;
int g[N][N];
int vis[N];
int height[N];
int stk[N];
int deep,top;
int mark[N];
int save[N]; //用来记录特殊状态
int ans; int dfs(int s,int num)
{
vis[s]=deep++;
stk[top++]=s;
height[s]=num;
int mi=vis[s];
for(int i=;i<=n;i++)
{
if(g[s][i]==) continue;
if(vis[i]==-) //这个点未被访问
{
dfs(i,num+);
if( vis[i]>=vis[s] )//表示这个圈与世无争,必须单独处理掉
{
//开始处理!
int cnt=;
int tcnt=;
int flag=;
while(stk[top-]!=s)
{
cnt++;
if(mark[stk[top-]]==) flag=;//表示这一堆有奇环
if(save[stk[top-]]==) tcnt++;
top--;
} if(flag==)//这一堆不存在奇环
{
save[s]=;
ans += cnt+-tcnt;
} }
else
{
mi = min(mi,vis[i]);
}
}
else
{
mi=min(mi,vis[i]);//找当前能到达最上方的点
if( (height[s]-height[i])%== )//表示当前点在一个奇环中
mark[s]=;
}
}
vis[s]=mi;
return vis[s];
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&m,&k);
memset(g,,sizeof(g));
for(int i=;i<m;i++)
{
int x,y;
scanf("%d%d",&x,&y);
g[x][y]=g[y][x]=;
}
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
{
if(i==j) g[i][j]=;
else if(g[i][j]==) g[i][j]=;
else g[i][j]=;
}
//构建逆图
memset(vis,-,sizeof(vis));
memset(save,,sizeof(save));
memset(mark,,sizeof(mark));
deep=;
top=;
ans=;//表示有多少不能参与游戏
for(int i=;i<=n;i++)
{
if(vis[i]==-)
{
dfs(i,);
}
}
if(ans<k) printf("What a Pity.\n");
else printf("Let's Fire!\n");
}
return ;
}
fzu2181(点的双连通分量+求奇环)的更多相关文章
- [cf557d]Vitaly and Cycle(黑白染色求奇环)
题目大意:给出一个 n 点 m 边的图,问最少加多少边使其能够存在奇环,加最少边的情况数有多少种. 解题关键:黑白染色求奇环,利用数量分析求解. 奇环:含有奇数个点的环. 二分图不存在奇环.反之亦成立 ...
- 【HDU4612】 双连通分量求桥
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4612 题目大意:给你一个无向图,问你加一条边后最少还剩下多少多少割边. 解题思路:好水的一道模板题.先 ...
- hdoj 4612 Warm up【双连通分量求桥&&缩点建新图求树的直径】
Warm up Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Su ...
- zoj 2588 Burning Bridges【双连通分量求桥输出桥的编号】
Burning Bridges Time Limit: 5 Seconds Memory Limit: 32768 KB Ferry Kingdom is a nice little cou ...
- Codeforces 962 /2错误 相间位置排列 堆模拟 X轴距离最小值 前向星点双连通分量求只存在在一个简单环中的边
A #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #def ...
- poj 1144 Network【双连通分量求割点总数】
Network Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11042 Accepted: 5100 Descript ...
- hdoj 3849 By Recognizing These Guys, We Find Social Networks Useful【双连通分量求桥&&输出桥&&字符串处理】
By Recognizing These Guys, We Find Social Networks Useful Time Limit: 2000/1000 MS (Java/Others) ...
- hdoj 4738 Caocao's Bridges【双连通分量求桥】
Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 1689 求奇环bfs关键是层次图
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<queue> usin ...
随机推荐
- [TypeScript] Create Explicit and Readable Type Declarations with TypeScript mapped Type Modifiers
Using the optional “+” sign together with mapped type modifiers, we can create more explicit and rea ...
- ubuntu14.10环境下使用apache2.2配置代理服务器
参考网址: 使用Apache架设代理服务器 ubuntu之apache正向代理及反向代理(ProxyPass\ProxyPassReverse) Apache配置正向代理与反向代理 我的配置步骤: 1 ...
- Unity 配置静态excel 工作流程
TP:FCEE652B cause how improvement cause 在游戏开发的过程中,很多时候需要策划填的一些静态数据表(比如英雄表,技能表等等),而策划一般都习惯使用excel. ex ...
- html checkbox 实现全选/取消全选
html checkbox 实现全选/取消全选 <html> <body> <table border="1"> <tr> < ...
- android logo设计
应用程序图标 (Icon)应当是一个 Alpha 通道透明的32位 PNG 图片.由于安卓设备众多,一个应用程序图标需要设计几种不同大小,如: LDPI (Low Density Screen,120 ...
- struts2 接口如何接收客户端提交的json数据
struts2 接口如何接收客户端提交的json数据 CreationTime--2018年6月20日15点54分 Author:Marydon 1.情景还原 使用struts2写的接口(服务端) ...
- struts上传文件 血案
记录一个图片上传之后没有后缀 拓展名问题 平常我们查询数据都是 fileImage=fileImageService.getQuery(); 让entity等于它 那么fileImage.getF ...
- 【CODEFORCES】 C. Table Decorations
C. Table Decorations time limit per test 1 second memory limit per test 256 megabytes input standard ...
- CentOS 7中mariadb编译安装教程systemctl启动
mariadb做为mysql的替代品 现在centos的新版本yum包已换成mariadb 跟上篇一样只是启动方式改为systemd 安装一些库 yum install gcc gcc-c++ wge ...
- atitit.taskService 任务管理器的设计 v1
atitit.taskService 任务管理器的设计 v1 任务管理器的点 Sametime_exe_count Per task sleepMillSec Timeout_secs 作者:: 绰号 ...