传送门

分析

此题要先用tarjan求点双联通分量,注意在求解是要注意一条无向边只能走一次。求完之后我们发现原来的图会变成一棵树,对于 这棵树我们发现答案是(叶子节点数量+1)/2,实际便是每两个节点之间连一条边。

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
int dfn[],low[],ist[],cnt,sum,belong[],id[],ans;
vector<int>v[];
vector<int>nv[];
stack<int>a;
inline void tarjan(int x,int fa){
dfn[x]=low[x]=++cnt;
a.push(x);
ist[x]=;
int wh=;
for(int i=;i<v[x].size();i++){
if(v[x][i]==fa&&!wh){
wh=;
continue;
}
if(!dfn[v[x][i]]){
tarjan(v[x][i],x);
low[x]=min(low[x],low[v[x][i]]);
}else if(ist[v[x][i]]){
low[x]=min(low[x],dfn[v[x][i]]);
}
}
if(dfn[x]==low[x]){
sum++;
while(){
int u=a.top();
a.pop();
ist[u]=;
belong[u]=sum;
if(u==x)break;
}
}
return;
}
int main(){
int n,m,i,j,k,x,y;
scanf("%d%d",&n,&m);
for(i=;i<=m;i++){
scanf("%d%d",&x,&y);
v[x].push_back(y);
v[y].push_back(x);
}
tarjan(,);
for(i=;i<=n;i++)
for(j=;j<v[i].size();j++)
if(belong[i]!=belong[v[i][j]])
id[belong[v[i][j]]]++;
for(i=;i<=sum;i++)
if(id[i]==)ans++;
printf("%d\n",(ans+)/);
return ;
}

loj10098 分离的路径的更多相关文章

  1. 从字符串总分离文件路径、命名、扩展名,Substring(),LastIndexOf()的使用;替换某一类字符串,Replace()的用法

    一:从字符串总分离文件路径.命名.扩展名,上图 二:代码 using System; using System.Collections.Generic; using System.ComponentM ...

  2. BZOJ 1718: [Usaco2006 Jan] Redundant Paths 分离的路径( tarjan )

    tarjan求边双连通分量, 然后就是一棵树了, 可以各种乱搞... ----------------------------------------------------------------- ...

  3. BZOJ1718:[USACO]Redundant Paths 分离的路径(双连通分量)

    Description In order to get from one of the F (1 <= F <= 5,000) grazing fields (which are numb ...

  4. webpack配置:图片处理、css分离和路径问题

    一.CSS中的图片处理: 1.首先在网上随便找一张图片,在src下新建images文件夹,将图片放在文件夹内 2.在index.html中写入代码:<div id="pic" ...

  5. 【bzoj1718】Redundant Paths 分离的路径

    1718: [Usaco2006 Jan] Redundant Paths 分离的路径 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 964  Solve ...

  6. [Usaco2006 Jan] Redundant Paths 分离的路径

    1718: [Usaco2006 Jan] Redundant Paths 分离的路径 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1132  Solv ...

  7. [BZOJ1718]:[Usaco2006 Jan] Redundant Paths 分离的路径(塔尖)

    题目传送门 题目描述 为了从F个草场中的一个走到另一个,贝茜和她的同伴们有时不得不路过一些她们讨厌的可怕的树.奶牛们已经厌倦了被迫走某一条路,所以她们想建一些新路,使每一对草场之间都会至少有两条相互分 ...

  8. Redundant Paths 分离的路径【边双连通分量】

    Redundant Paths 分离的路径 题目描述 In order to get from one of the F (1 <= F <= 5,000) grazing fields ...

  9. Redundant Paths 分离的路径

    Redundant Paths 分离的路径 题目描述 为了从F(1≤F≤5000)个草场中的一个走到另一个,贝茜和她的同伴们有时不得不路过一些她们讨厌的可怕的树.奶牛们已经厌倦了被迫走某一条路,所以她 ...

随机推荐

  1. hdoj-2141-Can you find it?(二分查找)

    题目链接 /* Name:HDU-2141-Can you find it? Copyright: Author: Date: 2018/4/12 17:15:46 Description: 暴力,复 ...

  2. python_安装python2.7.7和easy_install

    [环境]: WIN7 + 32位 [要求]: 安装python2.7.7, easy_install 1. 下载并安装python2.7.7 首先访问http://www.python.org/dow ...

  3. 3.4 常用的两种 layer 层 3.7 字体与文本

    3.4 常用的两种 layer 层  //在cocos2d-x中,经常使用到的两种 layer 层 : CCLayer 和 CCLayerColor //CCLayer 的创建 CCLayer* la ...

  4. HDU - 1506 Largest Rectangle in a Histogram (单调栈/笛卡尔树)

    题意:求一个直方图中最大矩形的面积. 很经典的一道问题了吧,可以用单调栈分别求出每个柱子左右两边第一个比它低的柱子(也就相当于求出了和它相连的最后一个比它高的柱子),确定每个柱子的左右边界,每个柱子的 ...

  5. UVA - 1471 Defense Lines (set/bit/lis)

    紫薯例题+1. 题意:给你一个长度为n(n<=200000)的序列a[n],求删除一个连续子序列后的可能的最长连续上升子序列的长度. 首先对序列进行分段,每一段连续的子序列的元素递增,设L[i] ...

  6. VS2005环境下的DLL应用

    VS2005环境下的DLL应用 作者:一点一滴的Beer http://beer.cnblogs.com/ 以前写过一篇题为<VC++的DLL应用(含Demo演示)>的文章,当时是刚开始接 ...

  7. 【转载,实测好用】gitlab结合sourcetree使用

    转载 的出处http://blog.csdn.net/u012764358/article/details/62886427 Gitlab和Sourcetree结合使用实现代码管理 这是本人第一次发表 ...

  8. 如何批量清除128组节点db上面的过期的binlog,释放磁盘空间。(转)

    如果10台以内的db的话,自己手动ssh进去,clean就足以,但是上百台呢,就要写脚本了.大概思路:在 一台db跳转机上面, 写一个脚本,访问slave,远程获取正在复制的master上面的binl ...

  9. pos机的热敏纸尺寸

    57x50或者是57x30,两个型号宽度都是一样的,只是厚度不一样,前者是厚一点,适合固定机用,后者适合移动POS机用 厚度不是指纸的厚度,而是纸的容量,移动机的纸槽较小只能用57X30的

  10. [机器学习基础]矩阵基础和numpy

    矩阵定义:[摘自百度百科] 由 m × n 个数aij排成的m行n列的数表称为m行n列的矩阵,简称m × n矩阵.记作: 这m×n 个数称为矩阵A的元素,简称为元,数aij位于矩阵A的第i行第j列,称 ...