HDU3394:Railway
点双练习。
对于一张图,询问有多少条边不属于任意一个点双和多少条边至少属于两个点双。
显然,一张图里有多少个桥就是第一问的答案。
对于第二问,考虑对于一个点双,如果其中的边数等于点数,那么这个点双就是一个简单环,如果边数大于点数,那么这个点双里的所有边都至少属于两个点双。
证明的话画个图看看就好啦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的更多相关文章
- HDU3394 Railway —— 点双联通分量 + 桥(割边)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3394 Railway Time Limit: 2000/1000 MS (Java/Others) ...
- HDU3394 Railway 题解(边双连通分量)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3394 题目大意: 给定一个无向图,如果从一个点出发经过一些点和边能回到该点本身,那么一路走过来的这些点 ...
- 连通图(Tarjan算法) 专题总结
一.题目类型: 1.有向图的强连通分量: POJ1236 Network of Schools HDU1269 迷宫城堡 2.割点 & 割边: UESTC - 900 方老师炸弹 UVA315 ...
- 【HDU3394】Railway
[题目描述] 有一个公园有n个景点,公园的管理员准备修建m条道路,并且安排一些形成回路的参观路线.如果一条道路被多条道路公用,那么这条路是冲突的:如果一条道路没在任何一个回路内,那么这条路是不冲突的 ...
- BZOJ 2080: [Poi2010]Railway 双栈排序
2080: [Poi2010]Railway Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 140 Solved: 35[Submit][Statu ...
- Codeforces 335C Sorting Railway Cars
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- CF#335 Sorting Railway Cars
Sorting Railway Cars time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- 【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 ...
- 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 ...
随机推荐
- 在Outlook中查看预览SharePoint文档库的文档
本文概况 阅读时间: 约2分钟 适用版本:SharePoint Server 2010及以上 面向用户:普通用户,管理员 难度指数:★★☆☆☆ 在日常工作中,总有一些常用的文档需要经常打开查看,其实我 ...
- Atitit ftp原理与解决方案
Atitit ftp原理与解决方案 Deodeo sh shmayama ..search ftp.. 1. http和ftp都只是通信协议,就是只管传输那一块的,那为什么不能使用ftp来显示网页?? ...
- UIDatePicker
UIDatePickerDemo 效果 用法 1.导入文件(CustomDatePickerView.h/.m 和UIView+SetRect.h/.m) 2.在所要用到地方导入头文件 #impor ...
- yii2中如何使用modal弹窗之基本使用
作者:白狼 出处:http://www.manks.top/yii2_modal_baseuse.html 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接, ...
- python脚本后台运行
问题描述: 环境: CentOS6.4 一个用python写的监控脚本test1.py,用while True方式一直运行,在ssh远程(使用putty终端)时通过以下命令启动脚本: python t ...
- PHP严重致命错误处理:php Fatal error: Cannot redeclare class or function
1.错误类型:PHP致命错误 Error type: PHP Fatal error Fatal error: Cannot redeclare (a) (previously declared in ...
- kali linux之窥看女神上网隐私(ettercap+wireshark+zenmap +dsniff)
作者:小波 http://www.cnblogs.com/xiaobo-Linux/ 无聊就玩了玩,不要干一些坏事哟~~网上也有一些文章关于kali linux的,就实战了一番.kali是用的debi ...
- 安全测试 - 抓包工具BurpSuite
Brup SuiteBurpSuite是用于攻击web应用程序的集成平台.它包含了许多工具,并为这些工具设计了许多接口,以促进加快攻击应用程序的过程.所有的工具都共享一个能处理并显示HTTP消息,持久 ...
- oAuth 2.0 笔记
OAuth 2.0规范于2012年发布,很多大型互联网公司(比如:微信.微博.支付宝)对外提供的SDK中,授权部分基本上都是按这个规范来实现的. OAuth 2.0提供了4种基本的标准授权流程,最为复 ...
- Spring在非web应用中关闭IoC容器 (registerShutdownHook)
在基于web的ApplicationContext实现中,已有相应的实现来处理关闭web应用时恰当地关闭Spring IoC容器.但,如果你正在一个非web应用的环境下使用Spring的IoC容器,如 ...