uva 10972(边双连通分量)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=33804、
思路:和poj的一道题有点像,不过这道题图可能不连通,因此首先求边双连通分量,然后算每个连通分量的度数,显然叶子节点的度数为1,孤立点的度数为0,然后就是统计度数了,对于孤立点ans+=2,对于叶子节点,ans++。于是最后的答案就是(ans+1)/2了。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
#include <vector>
using namespace std;
#define MAXN 1111 int n, m, cnt, _count;
stack <int >S;
vector <vector<int > >g; int low[MAXN], dfn[MAXN], color[MAXN];
int degree[MAXN];
bool mark[MAXN];
void Tarjan(int u, int father)
{
low[u] = dfn[u] = ++ cnt;
S.push(u);
mark[u] = true;
for(int i = ; i < g[u].size(); i ++ ){
int v = g[u][i];
if(v == father)continue;
if(dfn[v] == ) {
Tarjan(v, u);
low[u] = min(low[u], low[v]);
} else if(mark[v]) {
low[u] = min(low[u], dfn[v]);
}
}
if(low[u] == dfn[u]){
int x;
_count++;
do {
x = S.top();
S.pop();
mark[x] = false;
color[x] = _count;
}while(x != u);
}
} int main()
{
int u, v, ans;
while(~scanf("%d %d", &n, &m)){
g.clear();
g.resize(n+);
while(m --){
scanf("%d %d",&u, &v);
g[u].push_back(v);
g[v].push_back(u);
}
memset(dfn, , sizeof(dfn));
memset(mark, false, sizeof(mark));
cnt = _count = ;
for(int i = ; i <= n; i ++){
if(dfn[i] == )Tarjan(i, -);
}
if(_count == ){
puts("");
continue;
}
memset(degree, , sizeof(degree));
for(int i = ; i <= n; i++){
for(int j = ; j < g[i].size(); j++){
if(color[i] != color[g[i][j]])degree[color[g[i][j]]] ++;
}
}
ans = ;
for(int i = ; i <= _count; i++){
if(degree[i] == )ans += ; // 孤立点
else if(degree[i] == )ans ++; // 叶子节点
}
printf("%d\n", (ans + )/ );
}
return ;
}
uva 10972(边双连通分量)的更多相关文章
- 训练指南 UVA - 11324(双连通分量 + 缩点+ 基础DP)
layout: post title: 训练指南 UVA - 11324(双连通分量 + 缩点+ 基础DP) author: "luowentaoaa" catalog: true ...
- UVA 10972 - RevolC FaeLoN(边-双连通分量)
UVA 10972 - RevolC FaeLoN option=com_onlinejudge&Itemid=8&page=show_problem&category=547 ...
- UVA 10765 Doves and bombs(双连通分量)
题意:在一个无向连通图上,求任意删除一个点,余下连通块的个数. 对于一个非割顶的点,删除之后,原图仍连通,即余下连通块个数为1:对于割顶,余下连通块个数>=2. 由于是用dfs查找双连通分量,树 ...
- UVA 10972 RevolC FaeLoN(边-双连通+缩点)
很好的一道图论题,整整撸了一上午... 题意是给定一个无向图,要求将所有边变为有向边,求最少加入多少条有向边,使得该图强连通?这里先假设一个问题:给定一个无向子图,该子图具有怎样的性质才能使得将其无向 ...
- LA 3523 圆桌骑士(二分图染色+点双连通分量)
https://vjudge.net/problem/UVALive-3523 题意: 有n个骑士经常举行圆桌会议,商讨大事.每次圆桌会议至少应有3个骑士参加,且相互憎恨的骑士不能坐在圆桌旁的相邻位置 ...
- poj 2942 Knights of the Round Table(无向图的双连通分量+二分图判定)
#include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> #includ ...
- POJ2942 Knights of the Round Table[点双连通分量|二分图染色|补图]
Knights of the Round Table Time Limit: 7000MS Memory Limit: 65536K Total Submissions: 12439 Acce ...
- 【Codefoces487E/UOJ#30】Tourists Tarjan 点双连通分量 + 树链剖分
E. Tourists time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard inpu ...
- 【BZOJ-2730】矿场搭建 Tarjan 双连通分量
2730: [HNOI2012]矿场搭建 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1602 Solved: 751[Submit][Statu ...
随机推荐
- Linux中iptables设置详细(转)
无论如何,iptables是一个需要特别谨慎设置的东西,万一服务器不在你身边,而你贸然设置导致无法SSH,那就等着被老板骂吧,呵呵... 以下内容是为了防止这种情况发生而写的,当然很初级,不过一般服务 ...
- Ubuntu格式化分区时的一个小错误
admin@gpc:/$ sudo mkfs -t ext3 -c /dev/sdb1 mkfs.ext3: inode_size (128) * inodes_count (0) too big ...
- swift中文文档翻译之--字符串和字符
字符串和字符 A string is an ordered collection of characters, such as "hello, world" or "al ...
- C++中map的概念,与简单操作
来源:http://blog.csdn.net/wallwind/article/details/6876892 C++map学习 map<Key, Data, Compare, Allo ...
- jQuery类库的设计
目前为止,jquery是js社区中最活跃.用户最多的前端类库,具有链式操作.兼容性.基于数组的操作.强大的插件机制等特点,也是很多前端入门同学最早接触到的库.但是内部如何实现的,一直吸引着我.因此最近 ...
- Rescue
1039: Rescue Time Limit: 1 Sec Memory Limit: 32 MBSubmit: 1320 Solved: 306 Description Angel was c ...
- cpu和内存的关系
CPU是负责运算和处理的,内存是交换数据的.当程序或者操作者对CPU发出指令,这些指令和数据暂存在内存里,在CPU空闲时传送给CPU,CPU处理后把结果输出到输出设备上,输出设备就是显示器,打印机等. ...
- 专注docker安全:Security Scanning
导读 Docker毫无疑问是近期运维同学们的热点话题,Docker安全也由此倍受重视,Docker Security Scanning 是一款Docker镜像扫描的安全工具,目前已经在Docker C ...
- Item 表单页面的 Select2 相关业务逻辑
Select2 插件官网:https://select2.github.io/ Select2 初始化说明: 代码在 public/javascripts/subchannel_items.js 中的 ...
- 北工大耿丹学院16级计科院3班C语言课程助教学期总结
很荣幸得到邹老师,周老师,以及北工大耿丹学院各位老师的认可,担任计科院3班C语言课程助教,班主任为李光杰老师,很感谢李老师一学期的帮助,使得我更好的担任助教一职.我班学生31名,很愉快的与同学们度过一 ...