uva 10765 Doves and Bombs(割顶)
来源:互联网 发布:编发教学软件 编辑:程序博客网 时间:2024/06/05 05:11
题意:给定一个n个点的连通的无向图,一个点的“鸽子值”定义为将它从图中删去后连通块的个数。求每个点的“鸽子值”。
思路dfs检查每个点是否为割顶,并标记除去该点后有多少个连通分量
#include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> #include<iostream> #include<algorithm> #include<vector> #include<map> #include<queue> #include<stack> #include<string>#include<map> #include<set>#define eps 1e-6 #define LL long long using namespace std; const int maxn = 10000 + 100;const int INF = 0x3f3f3f3f;int n, m;vector<int> G[maxn];int val[maxn], node[maxn]; //node数组记录结点id间接排序 bool cmp(int x, int y) {return val[x] == val[y] ? x < y : val[x] > val[y];}int pre[maxn], dfs_clock;int dfs(int u, int fa) { //u在dfs树中的父节点为fa int lowu = pre[u] = ++dfs_clock;int child = 0; //子节点个数 for(int i = 0; i < G[u].size(); i++) {int v = G[u][i];if(!pre[v]) { //没有访问过v child++;int lowv = dfs(v, u);lowu = min(lowu, lowv); //用后代的low函数更新u的low函数 if(lowv >= pre[u]) {val[u]++;}}else if(pre[v] < pre[u] && v != fa) lowu = min(lowu, pre[v]); //用反向边更新u的low函数 } if(fa < 0 && child == 1) val[u] = 1;return lowu; } void init() {dfs_clock = 0;memset(pre, 0, sizeof(pre));for(int i = 0; i < n; i++) {G[i].clear();node[i] = i;val[i] = 1;}int x, y;while(scanf("%d%d", &x, &y) == 2 && x >= 0) {G[x].push_back(y);G[y].push_back(x);}}void solve() {dfs(0, -1);sort(node, node+n, cmp);for(int i = 0; i < m; i++) cout << node[i] << " " << val[node[i]] << endl; cout << endl;}int main() {//freopen("input.txt", "r", stdin);while(scanf("%d%d", &n, &m) == 2 && n) {init();solve();}return 0;}
0 0
- uva 10765 Doves and Bombs(割顶)
- uva 10765 - Doves and bombs(割点&BCC)
- UVA 10765 Doves and bombs
- Doves and bombs UVA, 10765
- UVA,10765 Doves and bombs
- UVa 10765 - Doves and bombs(割点,双连通分量)
- Doves and bombs UVA
- UVA - 10765 Doves and bombs (双联通分量)
- uva 10765 - Doves and bombs(连通分量)
- UVA 10765 Doves and bombs(强联通)
- UVA 10765 Doves and bombs(无向图求割点)
- uva 10765 Doves and bombs(双联通分量)
- UVA - 10765 Doves and bombs(双连通分量)
- (beginer)DFS (双连通分量) UVA 10765 Doves and bombs
- 10765 - Doves and bombs(双连通分量)
- UVA10765 Doves and bombs
- uva10765 - Doves and bombs
- Uva 10765 Doves and bombs (点双联通分量 + Block Forest Data Structure)
- python 基本类型list、tuple、dict学习
- spring IOC依赖注入
- 1--FreeRTOS操作系统介绍
- oracle系统表查询
- Xcode7 UI自动化测试详解 带demo UITests
- uva 10765 Doves and Bombs(割顶)
- 黑马程序员_集合2
- C#结构体与类区别
- Mybatis传递多个参数
- Min Stack
- C#DES对较大文件和文件字节数组对象加密解密
- LAMP环境配置与优化
- Android手游《斗地主》完整源码(支持单机和网络对战)
- 剑指offer 36 - 数组中的逆序对