TWO NODES

Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 2072    Accepted Submission(s): 683

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.

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.

Output

For each graph in the input, you should output the value of stab.

Sample Input


4 5
0 1
1 2
2 3
3 0
0 2

Sample Output


2

Source

2013 ACM-ICPC南京赛区全国邀请赛——题目重现

Recommend

zhuyuanchen520

/**********************我是分割线**************************/

12000秒,见过的时间最长的题目,发篇博客纪念一下

/**********************我是分割线**************************/

题意:

给你一个无向图,问你从这个无向图中删除任意两个点之后所能获得的独立连通分量个数的最大值.

分析:

12000秒,500个点,不暴一下真的对不起出题人。。。。

枚举要删的第一个点,然后Tarjan,Tarjan完事之后在找到删掉之后增加最多联通分量的点

代码:

  1 #include<bits/stdc++.h>
2 using namespace std;
3 const int MAXN = 10010;
4 const int MAXM = 100010;
5 struct Edge
6 {
7 int to, next;
8 bool cut;//是否为桥的标记
9 } edge[MAXM];
10 int head[MAXN], tot;
11 int Low[MAXN]; //low记录了某个点能到达的最晚标号
12 int DFN[MAXN]; //某个点遍历到的标号
13 int Index, top; //DFS的时钟
14 bool cut[MAXN]; //记录某个点是否是割顶
15 int add_block[MAXN]; //删除一个点后增加的连通块
16 int bridge;
17 void addedge(int u, int v)
18 {
19 edge[tot].to = v; edge[tot].next = head[u]; edge[tot].cut = false;
20 head[u] = tot++;
21 }
22 void Tarjan(int u, int pre,int f)
23 {
24 //cout<<333333<<endl;
25 int v;
26
27 Low[u] = DFN[u] = ++Index;
28
29 int son = 0;
30 for (int i = head[u]; i != -1; i = edge[i].next)
31 {
32 v = edge[i].to;
33 if (v == pre)continue;
34 if (v == f) continue;
35 if ( !DFN[v] )
36 {
37 son++;
38 Tarjan(v, u,f);
39 if (Low[u] > Low[v]) Low[u] = Low[v];
40 //割点
41 //一个顶点u是割点,当且仅当满足(1)或(2) (1) u为树根,且u有多于一个子树。
42 //(2) u不为树根,且满足存在(u,v)为树枝边(或称父子边,
43 //即u为v在搜索树中的父亲),使得DFS(u)<=Low(v)
44 if (u != pre && Low[v] >= DFN[u]) //不是树根
45 {
46 cut[u] = true;
47 add_block[u]++;
48 }
49 }
50 else if ( Low[u] > DFN[v]) //!!!
51 Low[u] = DFN[v];
52 }
53 //树根,分支数大于1
54 if (u == pre && son > 1)cut[u] = true;
55 if (u == pre)add_block[u] = son - 1;
56
57 }
58 int solve(int N)
59 {
60 int ori=0;
61 int ans = -1;
62 for(int j=0;j<N;j++){
63 ori=0;
64 memset(DFN,0,sizeof(DFN));
65 memset(add_block,0,sizeof(add_block));
66 memset(cut,false,sizeof(cut));
67 Index = top = 0;
68 bridge = 0;
69 for(int i = 0;i< N;i++)
70 if(i!=j&&!DFN[i]){
71 ori++;
72 Tarjan(i,i,j);
73 }
74 for(int i = 0;i <N;i++){
75 if(i!=j)
76 ans=max(ans,add_block[i]+ori);
77 }
78 }
79 return ans;
80 }
81
82 int main()
83 {
84 int n,m;
85 int u,v;
86 while(~scanf("%d%d",&n,&m)){
87 memset(head,-1,sizeof(head));
88 tot=0;
89 for(int i=0;i<m;i++){
90 scanf("%d%d",&u,&v);
91 addedge(u,v);
92 addedge(v,u);
93 }
94 printf("%d\n",solve(n));
95 }
96 }
97

HDU4587--TWO NODES(无向图割点,暴力出奇迹)这是我见过的时间最长的题。。。的更多相关文章

  1. SID1190471 / 烦人的幻灯片 暴力出奇迹 !!!!!!!!!!!!!!!!!!

    PID221 / 烦人的幻灯片 ☆ 提交你的代码 查看讨论和题解 你还木有做过哦 我的状态         查看最后一次评测记录 质量还不能统计出来哦~ 题目评价 质量 无 ★★★★★ ★★★★☆ ★ ...

  2. 紫书 习题 8-2 UVa 1610 (暴力出奇迹)

    这道题我真的想的非常的复杂, 拿草稿纸一直在找规律,推公式, 然后总有一些特殊的情况. 然后就WA了N次.无奈之下看了别人的博客, 然后就惊了.直接暴力枚举两个相邻字符串 里面的所有可能就可以了--真 ...

  3. Codeforces Round VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM 暴力出奇迹!

    VK Cup 2015 - Round 1 (unofficial online mirror, Div. 1 only)E. The Art of Dealing with ATM Time Lim ...

  4. Prime Matrix(暴力出奇迹)

    Description You've got an n × m matrix. The matrix consists of integers. In one move, you can apply ...

  5. Codeforces - 570D 离散DFS序 特殊的子树统计 (暴力出奇迹)

    题意:给定一棵树,树上每个节点有对应的字符,多次询问在\(u\)子树的深度为\(d\)的所有节点上的字符任意组合能否凑成一个回文串 把dfs序存储在一个二维线性表中,一个维度记录字符另一个维度记录深度 ...

  6. 51nod——1285 山峰和分段(暴力出奇迹)

    要求每段的点数都一样,因此分的段数cnt肯定是n的因子,要求每段都有山峰,因此cnt肯定小于等于山峰数量.分段的宽度d=n/cnt,对山峰数量做一个前缀和,检查一下每一段的山峰数量是否没有增加即可. ...

  7. 【杂】暴力出奇迹,lz水数据

    做了个填涂颜色的题qwq 洛谷上的qwq,然后我就把这道题水过去了qwq(显然这是不对的,我们不能水数据qwq)当然我本身是80分的qwq end-

  8. Post Lamps CodeForces - 990E(暴力出奇迹?)

    题意: 在一个从0开始的连续区间上  放置几个小区间,使得这些小区间覆盖整个大区间,不同长度的小区间有不同的花费,其中有m个点,小区间的左端点不能放在这些点上 解析: 显然如果0是这m点中的一个 则无 ...

  9. Manthan, Codefest 16 H. Fibonacci-ish II 大力出奇迹 莫队 线段树 矩阵

    H. Fibonacci-ish II 题目连接: http://codeforces.com/contest/633/problem/H Description Yash is finally ti ...

随机推荐

  1. python_0基础开始_day06

    第六节 1.小数据池 ==,is,id ==:查看等号两边的值是否一样 a = 9b = 9print(a == b) # 返回Truec = "dog"d = "dog ...

  2. leecode刷题(27)-- 合并k个排序链表

    leecode刷题(27)-- 合并k个排序链表 合并k个排序链表 合并 k 个排序链表,返回合并后的排序链表.请分析和描述算法的复杂度. 示例: 输入: [ 1->4->5, 1-> ...

  3. 02 Redis防止入侵

    在使用云服务器时,安装的redis3.0+版本都关闭了protected-mode,因而都遭遇了挖矿病毒的攻击,使得服务器99%的占用率!! 因此我们在使用redis时候,最好更改默认端口,并且使用r ...

  4. 请手写代码实现一个promise

    第一步:promise的声明 class Promise{ // 构造器 constructor(executor){ // 成功 let resolve = () => { }; // 失败 ...

  5. JS常用自定义函数总结

    JS常用自定义函数总结   1.原生JavaScript实现字符串长度截取 2.原生JavaScript获取域名主机 3.原生JavaScript清除空格 4.原生JavaScript替换全部 5.原 ...

  6. 【版本控制工具】 Git基础

    一.Git简介 Git 是一个开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目.于是Git 成了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制软件. (Git目前使用率非常 ...

  7. 超详细思路讲解SQL语句的查询实现,及数据的创建。

    最近一直在看数据库方面的问题,总结了一下SQL语句,这是部分详细的SQL问题,思路讲解: 第一步:创建数据库表,及插入数据信息 --Student(S#,Sname,Sage,Ssex) 学生表 CR ...

  8. kvm虚拟机热迁移

    一.热迁移描述: 相比KVM虚拟机冷迁移中需要拷贝虚拟机虚拟磁盘文件,kvm虚拟机热迁移无需拷贝虚拟磁盘文件,但是需要迁移到的宿主机之间需要有相同的目录结构虚拟机磁盘文件,也就是共享存储,本文这部分内 ...

  9. 修改linux系统TCP连接数

    修改linux系统TCP连接数 centOS 6.x (1)vi /etc/sysctl.conf (2)添加参数 net.nf_conntrack_max = 655360 (3)sysctl -p ...

  10. nginx配置详解---学校资料

    #配置worker进程运行用户 nobody也是一个linux用户,一般用于启动程序,没有密码 user nobody; #配置工作进程数目,根据硬件调整,通常等于CPU数量或者2倍于CPU数量 wo ...