传送门

点双练习。

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

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

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

证明的话画个图看看就好啦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. 深入理解DOM节点类型第二篇——文本节点Text

    × 目录 [1]特征 [2]空白 [3]属性[4]方法[5]性能 前面的话 文本节点顾名思义指向文本的节点,网页上看到的文字内容都属于文本节点.该节点简单直观,本文将详细介绍该部分内容 特征 文本节点 ...

  2. Android之RecyclerView的原生Bug-Inconsistency detected. Invalid view holder adapter positionViewHolder{a1bbfa3 position=2 id=-1, oldPos=-1, pLpos:-1 no parent}

    今天在运行自己编写的App时,突然发现App在运行时闪退,然后就查看了Android Studio的Log,发现了这个错误,上网查了一下,才知道是RecyclerView的原生Bug,在数据更新时会出 ...

  3. luke使用

    Luke介绍 Luke是一个方便的索引查看和诊断工具,可以访问Lucene构建的索引文件,显示和修改某些索引内容.能提供: 通过document编号或term浏览索引 查看document内容,可复制 ...

  4. 详解Linux交互式shell脚本中创建对话框实例教程_linux服务器

    本教程我们通过实现来讲讲Linux交互式shell脚本中创建各种各样对话框,对话框在Linux中可以友好的提示操作者,感兴趣的朋友可以参考学习一下. 当你在终端环境下安装新的软件时,你可以经常看到信息 ...

  5. 树莓派 连接wifi与路由器ip绑定

    先推荐几个手机软件 在酷安网里应该能找到 1.JuiceSSH  橘子ssh软件  手机连上路由器 就可以控制局域网内的树莓派 2.VNC Viewer  远程桌面软件VNC 也是连接局域网的树莓派 ...

  6. Js IP转数字

    <script type="text/javascript"> function d2h(d) { return d.toString(16) } function h ...

  7. netty学习资料

    netty学习资料推荐官方文档和<netty权威指南>和<netty in action>这两本书.下面收集下网上分享的资料 netty官方参考文档 Netty 4.x Use ...

  8. Ubuntu 一直掉线 以及连不上网 解决办法

    新装了一个Ubuntu 系统16.04才使用的时候一切顺利 但是过了两三天  就会出现 频繁掉线的情况 于是上网找大神们的解决办法 把文件 /etc/ppp/options 里面的一个数值改大一点 l ...

  9. ubuntu 14.04 配置 jdk1.8

    自己在Ubuntu中安装jdk1.8的步骤,记录以方便以后查询. 将下载好的jdk安装包移到/usr/local目录中(我喜欢将自己安装的软件放在/usr/local目录中),解压缩 sudo tar ...

  10. 关于HTTP协议,一篇就够了

    HTTP简介 HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文本到本地浏览器的传送 ...