传送门

分析

此题要先用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. model1 就是jsp+javabean

  2. 20165210 Java第九周学习总结

    20165210 Java第九周学习总结 教材学习内容 - 第十三章学习总结 URL类: URL的构造方法: try { URL url = new URL("http://www.goog ...

  3. UVALive 3971 Assemble(二分+贪心)

    本题思路不难,但是要快速准确的AC有点儿考验代码功力. 看了大白书上的标程,大有所获. 用map和vector的结合给输入分组,这个数据结构的使用非常精美,恰到好处. #include<iost ...

  4. OpenCV - Android Studio 2.2 中利用CAMKE进行OpenCV的NDK开发

    我在http://www.cnblogs.com/fx-blog/p/8206737.html一文中提到了如何在Android Studio中Java层导入OpenCV(包含opencv_contri ...

  5. linux下使用fstat来计算文件的大小

    #include <sys/types.h>#include <sys/stat.h>#include <unistd.h>#include <fcntl.h ...

  6. python爬虫框架Pyspider初次接触

    pyspider网站地址:http://docs.pyspider.org/en/latest/.文档比较好,安装起来也非常方便.既然是基于python的框架,那么首先得安装python.微软出的一款 ...

  7. Unity3D的SystemInfo类,用于获取运行设备硬件信息(CPU、显卡、类型等)

    SystemInfo类中的静态变量:   中文显示: Rendering.CopyTextureSupport copyTextureSupport:(只读)支持多种复制纹理功能的情况. string ...

  8. ELK多种架构及优劣

    圈子里关于大数据.云计算相关文章和讨论是越来越多,愈演愈烈.行业内企业也争前恐后,群雄逐鹿.而在大数据时代的运维挑站问题也就日渐突出,任重而道远了.本文旨在针对复杂的大数据运维系统推荐一把利器,达到抛 ...

  9. hl7消息中和时间有关的字段的格式

    hl7消息中有许多segment(段)包含时间类型的Field.常用的MSH, EVN, PID中的时间字段及其格式为: 1. MSH-7, Date/time Of Message为yyyyMMdd ...

  10. 开启VMSS Autoscale的报警功能

    VMSS可以自动的实现Scale Out和Scale in.在VMSS做自动操作的时候,可以通过配置通知服务,通知VMSS的状态. 具体实现方式: 1, 在portal中选择"监视器&quo ...