传送门

点双练习。

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

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

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

证明的话画个图看看就好啦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. View and Data API Tips: Hide elements in viewer completely

    By Daniel Du With View and Data API, you can hide some elements in viewer by calling "viewer.hi ...

  2. Linux Standards Base LSB

    LSB简介 http://www.ibm.com/developerworks/cn/linux/l-lsb-intr/ http://refspecs.linuxbase.org/ http://t ...

  3. MBProgressHUD 显示后,为何不能点击屏幕其他地方

    解决办法: hud.userInteractionEnabled= NO;  就是这么简单粗暴!这个问题 我一定要发到首页候选区! /********************************* ...

  4. eclipse调试(debug)的时候,出现Source not found,Edit Source Lookup Path,一闪而过

    问题描述 使用Eclipse调试代码的时候,打了断点,经常出现Source not found,网上找了半天,大部分提示点击Edit Source Lookup Path,添加被调试的工程,然而往往没 ...

  5. 【译】Spring 4 基于TaskScheduler实现定时任务(注解)

    前言 译文链接:http://websystique.com/spring/spring-job-scheduling-with-scheduled-enablescheduling-annotati ...

  6. [Erlang 0118] Erlang 杂记 V

       我在知乎回答问题不多,这个问题: "对你职业生涯帮助最大的习惯是什么?它是如何帮助你的?",我还是主动回答了一下.    做笔记 一开始笔记软件做的不好的时候就发邮件给自己, ...

  7. 从配置读取一段时间(TimeSpan)

    C#的TimeSpan表示一段时间,DateTime表示一个时间点.TimeSpan可正可负,可与DateTime相加减,很方便,我喜欢. 代码中我们经常要表示一段时间,用一个统一的单位(时 或者 分 ...

  8. MySQL:procedure, function, cursor,handler

    Procedure & Function Procedure 语法: CREATE [DEFINER = { user | CURRENT_USER }] PROCEDURE sp_name ...

  9. JavaScript如何获取网页url中的参数

    我们可以自定义一个公共函数来实现网页url中的参数获取,返回的是一个数组 GetUrlRequest: function () { var url = decodeURI(location.searc ...

  10. 用css改变默认的checkbox样式

    自己常用的改变checkbox样式的两个方法: 一.利用background用图片代替checkbox效果 缺点:你首先得有一张好看的图片 优点:浏览器兼容性好 <!doctype html&g ...