HDU 4587 (割点)
来源:互联网 发布:程序员怎么挣钱 编辑:程序博客网 时间:2024/06/05 17:43
TWO NODES
Time Limit: 24000/12000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 1618 Accepted Submission(s): 502
Problem Description
Suppose that G is an undirected graph, and the value of stab is defined as follows:
Among the expression,G-i, -j is the remainder after removing node i, node j and all edges that are directly relevant to the previous two nodes. cntCompent is the number of connected components of X independently.
Thus, given a certain undirected graph G, you are supposed to calculating the value of stab.
Among the expression,G-i, -j is the remainder after removing node i, node j and all edges that are directly relevant to the previous two nodes. cntCompent is the number of connected components of X independently.
Thus, given a certain undirected graph G, you are supposed to calculating the value of stab.
Input
The input will contain the description of several graphs. For each graph, the description consist of an integer N for the number of nodes, an integer M for the number of edges, and M pairs of integers for edges (3<=N,M<=5000).
Please note that the endpoints of edge is marked in the range of [0,N-1], and input cases ends with EOF.
Please note that the endpoints of edge is marked in the range of [0,N-1], and input cases ends with EOF.
Output
For each graph in the input, you should output the value of stab.
Sample Input
4 50 11 22 33 00 2
Sample Output
2
题意:求一个图去掉两个点之后的最多的联通分量数.
首先枚举一个去掉的点,然后求出所有的割点,对于所有的割点,他能够遍历到的点并
且没有访问过的点数就是删去他能够增加的联通分量数.
坑点:
注意树根和孤立节点的情况.
#include <iostream>#include <algorithm>#include <string.h>#include <stdio.h>#include <map>#include <vector>#include <stack>#include <queue>#include <math.h>#include <stdlib.h>using namespace std;const int maxn = 5111;const int maxm = 11111;typedef long long ll;int n, m;struct node { int u, v, next;}edge[maxm];int head[maxn], cnt;void add_edge (int u, int v) { edge[cnt].u = u, edge[cnt].v = v, edge[cnt].next = head[u], head[u] = cnt++;}int dfs_clock, pre[maxn], low[maxn], cur, ans;bool is_cut[maxn];int dfs (int u, int fa, int del) { int lowu = pre[u] = ++dfs_clock; int child = 0, curnum = 0; for (int i = head[u]; i != -1; i = edge[i].next) { int v = edge[i].v; if (v == del)//删掉的点 continue; if (!pre[v]) { child++; int lowv = dfs (v, u, del); lowu = min (lowu, lowv); if (lowv >= pre[u]) { is_cut[u] = 1; curnum++; } } else if (pre[v] < pre[u] && v != fa) { lowu = min (lowu, pre[v]); } } if (fa < 0 && child == 1) { is_cut[u] = 0; } if (child == 0 && fa < 0) { ans = max (ans, cur-1); } if (is_cut[u]) ans = max (ans, cur+curnum-(fa<0)); low[u] = lowu; return lowu;}int cc = 0;bool vis[maxn];void go (int u, int fa, int del) { cc++; vis[u] = 1; for (int i = head[u]; i != -1; i = edge[i].next) { int v = edge[i].v; if (v == fa || vis[v] || v == del) continue; go (v, u, del); }}int main () { //freopen ("in.txt", "r", stdin); while (scanf ("%d%d", &n, &m) == 2) { memset (head, -1, sizeof head); cnt = 0; for (int i = 1; i <= m; i++) { int u, v; scanf ("%d%d", &u, &v); add_edge (u, v); add_edge (v, u); } ans = 0; for (int i = 0; i < n; i++) {//枚举删掉的点 dfs_clock = 0; memset (is_cut, 0, sizeof is_cut); memset (pre, 0, sizeof pre); int u; cur = 0; memset (vis, 0, sizeof vis); bool ok = 0; for (u = 0; u < n; u++) if (!vis[u] && u != i) { cc = 0; go (u, -1, i); cur++; if (cc > 1) ok = 1; } if (cur == n-1) { ans = max (ans, n-2); continue; } if (ok) { ans = max (ans, cur); } for (u = 0; u < n; u++) if (!pre[u] && u != i) { dfs (u, -1, i);//找到所有的割点 } } printf ("%d\n", ans); } return 0;}
0 0
- HDU 4587 割点
- HDU 4587 (割点)
- HDU 4587 割点
- hdu 4587(割点的应用)
- Hdu 4587 TWO NODES(割点)
- 【割点】 HDU 4587 TWO NODES
- hdu 4587 TWO NODES (枚举+割点,5级)
- HDU 4587TWO NODES(割点,连通块,枚举)
- HDU 4587TWO NODES(割点,连通块,枚举)
- HDU-4587 TWO NODES (割点[Tarjan])
- [HDU 4587] TWO NODES (Tarjan+割点)
- HDU 4587 TWO NODES 无向图的割点
- hdu 4587 TWO NODES (割点的应用)
- HDU 4587 TWO NODES(割点 模板题)
- hdu 4587 判断孤立点+割点+ 删除点之后,剩下多少连通分量
- HDU-4587 TWO NODES(割点变形或者求点双连通分量)
- HDU 3491 Thieves 拆点 最小割
- hdu 3491(最小割+拆点)
- 基于Solr的空间搜索学习笔记
- Android程序去除标题栏
- 160. Intersection of Two Linked Lists
- PHP——函数_学习笔记
- 自定义拦截器没有加载
- HDU 4587 (割点)
- C/C++用new、delete分配回收堆中空间
- 特殊的String
- 随机梯度下降
- 数论之最大公约数和最小公倍数
- Android:Fragment 与 ViewPager的配合使用
- ViewPager导航图片——简单实现方法
- 单链表反转
- 【数据存储】——JSON的解析和生成