UVA 10765 (割点)
来源:互联网 发布:苗疆真的有蛊吗 知乎 编辑:程序博客网 时间:2024/05/21 17:28
题意:给出一个无向图,求出鸽子值,鸽子值即是每删除一个点后有多少个连通块。
思路:求割点,与割点相连的连通分量就是割点的鸽子值,非割点的点的鸽子值均为1。
#include <stdio.h>#include <stdlib.h>#include <iostream>#include <algorithm>#include <cstring>#include <math.h>#include <vector>#include <queue>#include <stack>using namespace std;vector <int> g[10010];struct C {int no, num;};C cut[10010];int dfs_clock;int pre[10010];bool comp(C a, C b){ if(a.num != b.num) return a.num > b.num; else return a.no < b.no;}int dfs(int u, int 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]) { child++; int lowv = dfs(v, u); lowu = min(lowu, lowv); if(lowv >= pre[u]) { cut[u].num++; } } else if(pre[v] < pre[u] && v != fa) { lowu = min(lowu, pre[v]); } } if(fa < 0 && child == 1) cut[u].num = 0; return lowu;}int main(){ int n, m; while(scanf("%d%d", &n, &m)) { if(n == 0 && m == 0) break; for(int i=0; i<10010; i++) { g[i].clear(); cut[i].no = i, cut[i].num = 0; } memset(pre, 0, sizeof(pre)); int x, y; while(scanf("%d%d", &x, &y)) { if(x == -1 && y == -1) break; g[x].push_back(y); g[y].push_back(x); } dfs_clock = 0; dfs(0, -1); sort(cut, cut+n, comp); for(int i = 0; i < m; i++) { printf("%d %d\n", cut[i].no, cut[i].num + 1); } printf("\n"); } return 0;}
0 0
- UVA 10765 (割点)
- 【割点】UVA
- UVA 315 Network (割点)
- uva 315 Network 割点
- uva 10765 - Doves and bombs(割点&BCC)
- UVa 10765 - Doves and bombs(割点,双连通分量)
- 割点、割边
- 割点、割边
- 割点 割边
- 割点、割边
- 割点
- 割点
- 割点
- 割点
- 【割点】
- 割点
- 割点
- 割点
- Android studio使用
- 数据库连接
- JSP学习笔记(四)---自定义标签
- leetcode 67: Add Binary
- android中Baseadapter的getItem和getItemId的作用和重写
- UVA 10765 (割点)
- hdu 1394 Minimum Inversion Number(线段树-单点更新)
- Java导出csv文件乱码的解决方法
- IOS中得block代码块的定义及使用
- 小项目实用makefile
- 二叉树的最低公共父节点
- 异地
- activiti
- Android HandlerThread 完全解析