传送门

解题思路

刚开始是找的桥,后来发现这样不对,因为一条链就可以被卡。后来想到应该缩点后找到度数为1 的点然后两两配对。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<set> using namespace std;
const int MAXN = ;
const int MAXM = ; inline int rd(){
int x=,f=;char ch=getchar();
while(!isdigit(ch)) {f=ch=='-'?:;ch=getchar();}
while(isdigit(ch)) {x=(x<<)+(x<<)+ch-'';ch=getchar();}
return f?x:-x;
} int n,m,head[MAXN],cnt,to[MAXM<<],nxt[MAXM<<],num,du[MAXN];
int dfn[MAXN],low[MAXN],ans,col[MAXN],col_num,stk[MAXN],top;
bool vis[MAXN];
set<pair<int,int> > S; inline void add(int bg,int ed){
to[++cnt]=ed,nxt[cnt]=head[bg],head[bg]=cnt;
} void tarjan(int x,int fa){
dfn[x]=low[x]=++num;vis[x]=;stk[++top]=x;int u;
for(register int i=head[x];i;i=nxt[i]){
u=to[i];if(u==fa) continue;
if(!dfn[u]) {tarjan(u,x);low[x]=min(low[x],low[u]);}
else if(vis[x])low[x]=min(low[x],dfn[u]);
}
if(low[x]!=dfn[x]) return;
col[x]=++col_num;vis[x]=;
while(stk[top]!=x) {
col[stk[top]]=col_num;
vis[stk[top--]]=;
}top--;
} int main(){
n=rd(),m=rd();int x,y;pair<int,int> p;
for(int i=;i<=m;i++){
x=rd(),y=rd();p=make_pair(x,y);
if(S.find(p)!=S.end()) continue;
S.insert(p);S.insert(make_pair(y,x));
add(x,y),add(y,x);
}
tarjan(,);
// for(int i=1;i<=n;i++) cout<<col[i]<<" ";
for(int i=;i<=n;i++)
for(int j=head[i];j;j=nxt[j])
if(col[i]!=col[to[j]]) du[col[i]]++,du[col[to[j]]]++;
for(int i=;i<=col_num;i++) if(du[i]==) ans++;
cout<<(ans+)/;
return ;
}

LUOGU P2860 [USACO06JAN]冗余路径Redundant Paths (双联通,缩点)的更多相关文章

  1. luogu P2860 [USACO06JAN]冗余路径Redundant Paths

    题目描述 In order to get from one of the F (1 <= F <= 5,000) grazing fields (which are numbered 1- ...

  2. 【luogu P2860 [USACO06JAN]冗余路径Redundant Paths】 题解

    题目链接:https://www.luogu.org/problemnew/show/P2860 考虑在无向图上缩点. 运用到边双.桥的知识. 缩点后统计度为1的点. 度为1是有一条路径,度为2是有两 ...

  3. luogu P2860 [USACO06JAN]冗余路径Redundant Paths |Tarjan

    题目描述 In order to get from one of the F (1 <= F <= 5,000) grazing fields (which are numbered 1. ...

  4. 洛谷 P2860 [USACO06JAN]冗余路径Redundant Paths 解题报告

    P2860 [USACO06JAN]冗余路径Redundant Paths 题目描述 为了从F(1≤F≤5000)个草场中的一个走到另一个,贝茜和她的同伴们有时不得不路过一些她们讨厌的可怕的树.奶牛们 ...

  5. 洛谷P2860 [USACO06JAN]冗余路径Redundant Paths(tarjan求边双联通分量)

    题目描述 In order to get from one of the F (1 <= F <= 5,000) grazing fields (which are numbered 1. ...

  6. P2860 [USACO06JAN]冗余路径Redundant Paths tarjan

    题目链接 https://www.luogu.org/problemnew/show/P2860 思路 缩点,之后就成了个树一般的东西了 然后(叶子节点+1)/2就是答案,好像贪心的样子,lmc好像讲 ...

  7. 洛谷P2860 [USACO06JAN]冗余路径Redundant Paths

    题目描述 In order to get from one of the F (1 <= F <= 5,000) grazing fields (which are numbered 1. ...

  8. P2860 [USACO06JAN]冗余路径Redundant Paths

    题解: 首先要边双缩点这很显然 然后变成树上问题 发现dp,dfs好像不太对 考虑一下度数 发现只要在度数为1的点之间连边 但我好像不太会证明这个东西.. 网上也没有看到比较正确的证明方法和连边策略. ...

  9. 缩点【洛谷P2860】 [USACO06JAN]冗余路径Redundant Paths

    P2860 [USACO06JAN]冗余路径Redundant Paths 为了从F(1≤F≤5000)个草场中的一个走到另一个,贝茜和她的同伴们有时不得不路过一些她们讨厌的可怕的树.奶牛们已经厌倦了 ...

随机推荐

  1. 2019-10-10-dotnet-新-sdk-style-项目格式的一些命名空间和引用

    title author date CreateTime categories dotnet 新 sdk style 项目格式的一些命名空间和引用 lindexi 2019-10-10 10:6:46 ...

  2. 提升方法(boosting)详解

    提升方法(boosting)详解 提升方法(boosting)是一种常用的统计学习方法,应用广泛且有效.在分类问题中,它通过改变训练样本的权重,学习多个分类器,并将这些分类器进行线性组合,提高分类的性 ...

  3. session复制

    环境描述:(三台服务器 系统:7.6)192.168.200.111 nginx192.168.200.112 tomcat192.168.200.113 tomcat环境配置:192.168.200 ...

  4. python指定概率随机取值 理解np.random.seed()

    python指定概率随机取值参考如下: 下面是利用 np.random.choice()指定概率取样的例子: np.random.seed(0) p = np.array([0.1, 0.0, 0.7 ...

  5. Tools: windbg 使用指南

    windbg使用 符号表C:\Symbols; SRV*C:\Symbols*http://msdl.microsoft.com/download/symbols 系统变量_NT_SYMBOL_PAT ...

  6. 使用threading模块创建线程

    #_author:来童星#date:2019/12/17#使用threading模块创建线程import threading,timedef process(): for i in range(3): ...

  7. windows 登陆服务器

    点击电脑的左下方开始,然后输入远字,如下图,就可以招到远程桌面了. 点击远程桌面就进入下图界面了.默认情况下,是在常规这个选项卡. 我们切换到显示,可以调节远程桌面的大小,一般我们设置成全屏显示.只要 ...

  8. fastJson中常用方法以及遇到的“坑”

    1.使用fastJson,首先引入fastJson依赖 <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson --> & ...

  9. DELPHI读取网页源文件和获取字符串

    说到网页采集,通常大家以为到网上偷数据,然后把到收集到的数据挂到自己网上去.其实也可以将采集到的数据做为公司的参考,或把收集的数据跟自己公司的业务做对比等.目前网页采集多为3P代码为多(3P即ASP. ...

  10. tarjan强连通分量 (模板)

    #include<iostream> #include<cstdio> using namespace std; const int MAXN = 10005; struct ...