1738 - TWO NODES
1738 - TWO NODES
时间限制: | 10000 MS |
内存限制: | 65535 KB |
问题描述
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(X) 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 consists of multiple cases.
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.
输出说明
For each graph in the input, you should output the value of stab.
输入样例
4 5
0 1
1 2
2 3
3 0
0 2
输出样例
2
来源
#include <iostream>
#include <stdio.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <stack>
#include <math.h>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#pragma comment(linker, "/STACK:10240000000000,10240000000000")
using namespace std;
typedef long long LL ;
const int Max_N= ;
struct Edge{
int v ;
int next ;
};
Edge edge[Max_N*] ;
int id ,indx ;
int vec[Max_N] ,dfn[Max_N] ,low[Max_N] ;
bool visited[Max_N];
void add_edge(int u ,int v){
edge[id].v=v ;
edge[id].next=vec[u] ;
vec[u]=id++ ;
}
void init(){
id= ;
indx= ;
memset(vec,-,sizeof(vec)) ;
}
int ans ,root_son ;
int can_use[Max_N] ; void dfs(int u ,bool is_root){
dfn[u]=low[u]=++indx ;
visited[u]= ;
int child = ;
for(int e=vec[u];e!=-;e=edge[e].next){
int v=edge[e].v ;
if(can_use[v]==)
continue ;
if(!dfn[v]){
dfs(v,) ;
if(is_root)
root_son++ ;
else{
low[u]=Min(low[u],low[v]) ;
if(low[v]>=dfn[u])
child++ ;
}
}
else
low[u]=Min(low[u],dfn[v]) ;
}
ans=Max(ans ,child+) ; //注意+1
} int tarjan(int root){
if(vec[root]==-) //块内就一个点的情况
return ;
memset(dfn,,sizeof(dfn)) ;
ans= ; //删除当前块里面的某点产生的分量数
root_son= ;
dfs(root,) ;
ans=Max(ans,root_son) ;
return ans ;
} int main(){
int N ,M ,u ,v ,ans ,child ,sum;
while(scanf("%d%d",&N,&M)!=EOF){
init() ;
sum= ;
while(M--){
scanf("%d%d",&u,&v) ;
add_edge(u,v) ;
add_edge(v,u) ;
}
memset(can_use,,sizeof(can_use)) ;
for(int k=;k<N;k++){
can_use[k]= ;
child= ;
ans= ;
memset(visited,,sizeof(visited)) ;
for(int i=;i<N;i++){
if(can_use[i]==)
continue ;
if(!visited[i]){
child++ ;
ans=Max(ans,tarjan(i)) ;
}
}
//cout<<child+ans-1<<endl ; //原来就有1块
int now=child+ans- ;
sum=Max(sum,now) ;
can_use[k]= ;
}
cout<<sum<<endl ;
}
return ;
}
1738 - TWO NODES的更多相关文章
- [LeetCode] Count Complete Tree Nodes 求完全二叉树的节点个数
Given a complete binary tree, count the number of nodes. Definition of a complete binary tree from W ...
- [LeetCode] Reverse Nodes in k-Group 每k个一组翻转链表
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. If ...
- [LeetCode] Swap Nodes in Pairs 成对交换节点
Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1->2-&g ...
- Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2-& ...
- Leetcode-24 Swap Nodes in Pairs
#24. Swap Nodes in Pairs Given a linked list, swap every two adjacent nodes and return its head. For ...
- No.025:Reverse Nodes in k-Group
问题: Given a linked list, reverse the nodes of a linked list k at a time and return its modified list ...
- No.024:Swap Nodes in Pairs
问题: Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1-> ...
- Reverse Nodes in k-Group
Reverse Nodes in k-Group Given a linked list, reverse the nodes of a linked list k at a time and ret ...
- Count Complete Tree Nodes
Given a complete binary tree, count the number of nodes. Definition of a complete binary tree from W ...
随机推荐
- linux创建git远程仓库
root用户 ============================ // 创建用户 >adduser newuser // 修改用户的密码 >passwd newuser // 设置权 ...
- jquery中关于append()的用法笔记---append()节点移动与复制之说
jquery中关于append()的用法笔记---append()节点移动与复制之说 今天看一本关于jquery的基础教程,看到其中一段代码关于append()的一行,总是百思不得其解.于是查了查官方 ...
- WPF4.5 中的新增功能和增强功能的信息
本主题包含有关 Windows Presentation Foundation (WPF) 版本 4.5 中的新增功能和增强功能的信息. 本主题包含以下各节: 功能区控件 改善性能,当显示大时设置分组 ...
- mongodb基本语句使用
mongodb学习:##mongodb基础##数据库常用命令##用户相关##修改.添加.删除集合数据##条件操作符##创建表 ------------------------------------- ...
- PHPNow升级PHP版本为5.3.5的方法
在WIN上有时候需要测试一些PHP程序,又不会自行独立配置环境,那么PHPNow是非常好的选择,这篇文章主要为大家分享下如果将phpnow的php版本升级为5.3.5 在WIN上有时候需要测试一些 ...
- grep,sed,cut,awk,join个性特点
grep 从数据文件中查询/提取出含有特定关键字的行. sed 主要用于对数据文件中特定字符串的替换处理. cut 按照指定的分隔符(-d)剪下选定的列(-f num)或者字符(-c)的内容. awk ...
- POJ 3709 K-Anonymous Sequence
题目大意:将一个升序的,有N个元素的序列,分组.要求每组的元素不少于K个,计算出组内各元素与最小元素的之差的和,将每组的这个值加起来,其和要最小. N<500000,K<N 分析: dp[ ...
- 黄聪:查看mysql数据库真正的data目录
终于找到了mysql数据库data目录在哪里! 用show variables like 'datadir',可查看真正的data目录 原文:http://blog.csdn.net/dmz1981/ ...
- (C# 基础) Datatable
增加一行: DataTable measurements = new DataTable(); measurements.Columns.Add("StationTestName" ...
- GL_GL系列 - 预算管理分析(案例)
2014-07-09 Created By BaoXinjian