传送门

解题思路

刚开始是找的桥,后来发现这样不对,因为一条链就可以被卡。后来想到应该缩点后找到度数为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. umount - 卸载文件系统

    总览 umount [-hV] umount -a [-nrv] [-t vfstype] umount [-nrv] device | dir [...] 描述 umount 可以卸除当前挂载在文件 ...

  2. 带各位深入理解java1.8之supplier

    supplier也是是用来创建对象的,但是不同于传统的创建对象语法:new,看下面代码:public class TestSupplier { private int age; (www.0831jl ...

  3. PDO基础

    //PDO:数据访问抽象层 $dsn = "mysql:dbname=mydb;host=localhost";//造PDO对象 $pdo = new PDO($dsn," ...

  4. 【SPOJ DQUERY】区间数字统计

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 因为区间的端点移动一个单位的话,只会涉及到一个元素的增多或减少. 因此可以用莫队算法来解决. 只需要开一个数组(大小1百万),用下标来快速检索 ...

  5. NX二次开发-UFUN计时函数UF_begin_timer

    NX9+VS2012 #include <uf.h> #include <uf_modl.h> UF_initialize(); //计时开始 UF_timer_t Timer ...

  6. Python 爬虫-爬取京东手机页面的图片

    具体代码如下: __author__ = 'Fred Zhao' import requests from bs4 import BeautifulSoup import os from urllib ...

  7. KdPrint/DbgPrint and UNICODE_STRING/ANSI_STRING

    typedef struct _UNICODE_STRING { USHORT Length; USHORT MaximumLength; PWSTR Buffer; } UNICODE_STRING ...

  8. centos7.4安装高可用(haproxy+keepalived实现)kubernetes1.6.0集群(开启TLS认证)

    目录 目录 前言 集群详情 环境说明 安装前准备 提醒 一.创建TLS证书和秘钥 安装CFSSL 创建 CA (Certificate Authority) 创建 CA 配置文件 创建 CA 证书签名 ...

  9. 20140319 const sizeof define 编译时分配内存

    1.面试宝典预处理,const,sizeof Define作用定义函数: //用一个宏定义FIND求一个结构体struc里某个变量相对于struc的偏移量,如FIND(student,a)//等于0 ...

  10. scanf 与getchar区别

    #include<stdio.h> void main() {    int c; c=getchar(); //scanf("%c",&c); if(c!=' ...