传送门

点双练习。

对于一张图,询问有多少条边不属于任意一个点双和多少条边至少属于两个点双。

显然,一张图里有多少个桥就是第一问的答案。

对于第二问,考虑对于一个点双,如果其中的边数等于点数,那么这个点双就是一个简单环,如果边数大于点数,那么这个点双里的所有边都至少属于两个点双。

证明的话画个图看看就好啦QAQ

//HDU 3394
//by Cydiater
//2016.11.2
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <map>
#include <ctime>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <bitset>
#include <set>
#include <cmath>
#include <vector>
using namespace std;
#define ll long long
#define up(i,j,n)		for(int i=j;i<=n;i++)
#define down(i,j,n)		for(int i=j;i>=n;i--)
#define cmax(a,b) 		a=max(a,b)
#define cmin(a,b)		a=min(a,b)
#define Auto(i,node)	for(int i=LINK[node];i;i=e[i].next)
#define vci vector<int>
const int MAXN=2e5+5;
const int oo=0x3f3f3f3f;
inline int read(){
	char ch=getchar();int x=0,f=1;
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int LINK[MAXN],len=0,dfn[MAXN],low[MAXN],stack[MAXN],top=0,dfs_clock=0,ans1,ans2,N,M,group[MAXN],group_num=0;
struct edge{
	int y,next;
}e[MAXN];
vci block;
namespace solution{
	void Clear(){
		len=ans1=ans2=dfs_clock=top=group_num=0;
		memset(LINK,0,sizeof(LINK));
		memset(dfn,0,sizeof(dfn));
		memset(low,0,sizeof(low));
		memset(group,0,sizeof(group));
	}
	inline void insert(int x,int y){e[++len].next=LINK[x];LINK[x]=len;e[len].y=y;}
	inline void Insert(int x,int y){insert(x,y);insert(y,x);}
	void init(){
		Clear();
		N=read();M=read();
		if(N==0)exit(0);
		up(i,1,M){
			int x=read(),y=read();
			Insert(x,y);
		}
	}
	void col(){
		int siz=block.size(),cnt=0;
		up(i,0,siz-1)Auto(j,block[i])if(group[e[j].y]==group_num)cnt++;
		cnt>>=1;
		if(cnt>siz)ans2+=cnt;
	}
	void tarjan(int node,int father){
		dfn[node]=low[node]=++dfs_clock;stack[++top]=node;
		Auto(i,node)if(!dfn[e[i].y]){
			tarjan(e[i].y,node);cmin(low[node],low[e[i].y]);
			if(low[e[i].y]>dfn[node])ans1++;
			if(low[e[i].y]>=dfn[node]){
				int tmp;block.clear();group_num++;
				do{
					tmp=stack[top--];
					block.push_back(tmp);
					group[tmp]=group_num;
				}while(tmp!=e[i].y);
				block.push_back(node);group[node]=group_num;
				col();
			}
		}else if(e[i].y!=father) cmin(low[node],dfn[e[i].y]);
	}
	void slove(){
		up(i,1,N)if(!dfn[i])tarjan(i,0);
		printf("%d %d\n",ans1,ans2);
	}
}
int main(){
	//freopen("input.in","r",stdin);
	using namespace solution;
	while(1){
		init();
		slove();
	}
	return 0;
}

HDU3394:Railway的更多相关文章

  1. HDU3394 Railway —— 点双联通分量 + 桥(割边)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3394 Railway Time Limit: 2000/1000 MS (Java/Others)   ...

  2. HDU3394 Railway 题解(边双连通分量)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3394 题目大意: 给定一个无向图,如果从一个点出发经过一些点和边能回到该点本身,那么一路走过来的这些点 ...

  3. 连通图(Tarjan算法) 专题总结

    一.题目类型: 1.有向图的强连通分量: POJ1236 Network of Schools HDU1269 迷宫城堡 2.割点 & 割边: UESTC - 900 方老师炸弹 UVA315 ...

  4. 【HDU3394】Railway

    [题目描述] 有一个公园有n个景点,公园的管理员准备修建m条道路,并且安排一些形成回路的参观路线.如果一条道路被多条道路公用,那么这条路是冲突的:如果一条道路没在任何一个回路内,那么这条路是不冲突的 ...

  5. BZOJ 2080: [Poi2010]Railway 双栈排序

    2080: [Poi2010]Railway Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 140  Solved: 35[Submit][Statu ...

  6. Codeforces 335C Sorting Railway Cars

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  7. CF#335 Sorting Railway Cars

    Sorting Railway Cars time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  8. 【CodeForces 605A】BUPT 2015 newbie practice #2 div2-E - Sorting Railway Cars

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/E Description An infinitely lon ...

  9. Codeforces Round #335 (Div. 2) C. Sorting Railway Cars 连续LIS

    C. Sorting Railway Cars   An infinitely long railway has a train consisting of n cars, numbered from ...

随机推荐

  1. 处理程序“ExtensionlessUrlHandler-Integrated-4.0”在其模块列表中有一个错误模块“ManagedPipelineHandler”

    新服务器安装完开发环境后,还需要注册framework4.0到IIS.不然会报错:   HTTP 错误 500.21 - Internal Server Error 处理程序“Extensionles ...

  2. 软件工程第二次作业——git的使用

    1. 参照 http://www.cnblogs.com/xinz/p/3803109.html 的第一题,每人建立一个GitHub账号,组长建立一个Project,将本组成员纳入此Porject中的 ...

  3. Html --用简单的<hr>实现多样化分割效果

    最基本的:<hr width=300 size=1 color=#5151A2 align=center noshade>. <!--其中 width 规定线条的长度,还可以是百分比 ...

  4. [MySQL性能优化系列]提高缓存命中率

    1. 背景 通常情况下,能用一条sql语句完成的查询,我们尽量不用多次查询完成.因为,查询次数越多,通信开销越大.但是,分多次查询,有可能提高缓存命中率.到底使用一个复合查询还是多个独立查询,需要根据 ...

  5. 萌新笔记——git的问题(error: object file .git/objects/* is empty...)的解决方案及对git版本库文件的了解

    由于操作不当,导致git版本库出了大问题,如下所示: error: object file .git/objects/8b/61d0135d3195966b443f6c73fb68466264c68e ...

  6. Swift和Objective-C混编注意事项

    前言 Swift已推出数年,与Objective-C相比Swift的语言机制及使用简易程度上更接地气,大大降低了iOS入门门槛.当然这对新入行的童鞋没来讲,的确算是福音,但对于整个iOS编程从业者来讲 ...

  7. 分布式监控系统Zabbix-3.0.3-完整安装记录(7)-使用percona监控MySQL

    前面已经介绍了分布式监控系统Zabbix-3.0.3-完整安装记录(2)-添加mysql监控,但是没有提供可以直接使用的Key,太过简陋,监控效果不佳.要想更加仔细的监控Mysql,业内同学们都会选择 ...

  8. PAT 1043. 输出PATest(20)

    给定一个长度不超过10000的.仅由英文字母构成的字符串.请将字符重新调整顺序,按"PATestPATest...."这样的顺序输出,并忽略其它字符.当然,六种字符的个数不一定是一 ...

  9. [LeetCode] Longest Repeating Character Replacement 最长重复字符置换

    Given a string that consists of only uppercase English letters, you can replace any letter in the st ...

  10. [LeetCode] Wiggle Sort 摆动排序

    Given an unsorted array nums, reorder it in-place such that nums[0] <= nums[1] >= nums[2] < ...