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 ...
随机推荐
- java读取properties文件的内容
获得properties文件中某个key对应着的value // 路径名称 + properties的名称,不要“properties” private static final String BUN ...
- UI-程序的运行顺序
在AppDelegate.m里面的每个方法里都输入(包括main文件里也输入) NSLog(@"%s %d”,__func__,__LINE__); __func__ :代表使用的方法 __ ...
- 【linux】grub加密
1.计算grub的MD5加密密码: #grub-md5-crypt Password: Retype password:输入两遍密码进行确认以后,就会计算出你所输入密码的MD5加密值,如:$1$pFd ...
- 【linux】/etc/fstab修复
/etc/fstab在修改后,如果配置错误直接重启的话会导致系统崩溃.建议大家重启前执行mount -a ,mount -a是自动挂载 /etc/fstab 里面的东西.若不慎重启了,会出现开机错误, ...
- ios外包公司—北京动点软件分享:IOS工程自动打包并发布脚本实现
前言 IOS的开发过程中,当需要给测试人员发布测试包的时候,直接使用xcode来做的效率是非常低下的.尤其是当有一点小改动需要重新出包时,那简直是个折磨的人的工作.通过一番研究后,遂决定写一系列脚本, ...
- LintCode "Backpack"
A simple variation to 0-1 Knapsack. class Solution { public: /** * @param m: An integer m denotes th ...
- 关于Tomcat自动加载更新class的小技巧
在Tomcat的server.xml或者Tomcat.xxx\conf\Catalina\localhost\project.xml文件中里Context标签内:<!-- reloadable为 ...
- Python之Fabric模块
Fabric是基于Python实现的SSH命令行工具,简化了SSH的应用程序部署及系统管理任务,它提供了系统基础的操作组件,可以实现本地或远程shell命令,包括:命令执行.文件上传.下载及完整执行日 ...
- 通过FTP自动上传当天的备份数据
@echo off del f:\ftpcfg.txt echo open 192.168.123.2>f:\ftpcfg.txt echo WMS>>f:\ftpcfg.txt e ...
- 使用 Override 和 New 关键字进行版本控制
使用 Override 和 New 关键字进行版本控制 C# 语言经过专门设计,以便不同库中的基类与派生类之间的版本控制可以不断向前发展,同时保持向后兼容. 这具有多方面的意义.例如,这意味着在基类中 ...