题意:n个点,m条边的无向图,有的边上有标记,每条边只能走一次

给你一个起点,一个终点,询问是否能找到从起点到终点的路径,这条路径至少包含一条含有标记的边

分析:然后边双缩点

下面介绍一下边双的性质

1,删掉边双内任意一条边,不影响边双的连通性

2,任取边双内两个点u,v,对于边双里面的任意一条边,至少包含于一条u到v的路径

所以对于这个题,可以运用上述的第二个性质,对于在边双里的标记边,都是可以经过的

然后缩点以后,变成一棵树,然后从起点所在的边双开始遍历,找到到终点所在边双的路径,询问权值是否大于0就行了

注意一点:这里的权值是点权加边权

#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
using namespace std;
const int N=3e5+;
int n,m,s,t;
struct Edge
{
int u,v,w,next;
} edge[N<<],e[N<<];
int head[N],tot,h[N];
void add(int u,int v,int w)
{
edge[tot].u=u;
edge[tot].v=v;
edge[tot].w=w;
edge[tot].next=head[u];
head[u]=tot++;
}
void adde(int u,int v,int w)
{
e[tot].v=v;
e[tot].w=w;
e[tot].next=h[u];
h[u]=tot++;
}
int pre[N],low[N],clk,bcc,bel[N];
stack<int>S;
void targin(int u,int f)
{
pre[u]=low[u]=++clk;
S.push(u);
for(int i=head[u]; ~i; i=edge[i].next)
{
int v=edge[i].v;
if(v==f)continue;
if(!pre[v])
{
targin(v,u);
low[u]=min(low[v],low[u]);
}
else low[u]=min(pre[v],low[u]);
}
if(pre[u]==low[u])
{
++bcc;
int k;
do
{
k=S.top();
S.pop();
bel[k]=bcc;
}
while(k!=u);
}
}
int val[N];
bool get(int u,int f,int sum)
{
sum+=val[u];
if(u==t)return sum;
for(int i=h[u]; ~i; i=e[i].next)
{
int v=e[i].v;
if(v==f)continue;
if(get(v,u,sum+e[i].w))return true;
}
return false;
}
int main()
{
scanf("%d%d",&n,&m);
memset(head,-,sizeof(head));
int tmp=;
for(int i=; i<=m; ++i)
{
int u,v,w;
scanf("%d%d%d",&u,&v,&w),tmp+=w;
add(u,v,w),add(v,u,w);
}
scanf("%d%d",&s,&t);
if(tmp==)
{
printf("NO\n");
return ;
}
targin(s,-);
tmp=tot;
memset(h,-,sizeof(h)),tot=;
for(int i=; i<tmp; i=i+)
{
int u=edge[i].u,v=edge[i].v;
u=bel[u],v=bel[v];
if(u==v)val[u]+=edge[i].w;
else adde(u,v,edge[i].w),adde(v,u,edge[i].w);
}
s=bel[s];
t=bel[t];
if(get(s,-,))printf("YES\n");
else printf("NO\n");
return ;
}

codeforces 652E Pursuit For Artifacts 边双连通分量的更多相关文章

  1. codeforces 652E . Pursuit For Artifacts 强连通分量

    题目链接 题目大意: 给一个图, n个点m条边, 某些边上面有权值. 一条边只能走一次, 给两个点s, t. 问你, 从s到t能否经过有权值的边. 首先肯定要缩点, 然后看同一个连通分量里面的边, 是 ...

  2. Codeforces 521E - Cycling City(点双连通分量+分类讨论)

    Codeforces 题面传送门 & 洛谷题面传送门 大家都是暴力找生成树然后跳路径,代码不到 50 行(暴论)的一说--好,那本蒟蒻决定提供一种代码 150 行,但复杂度也是线性的分类讨论做 ...

  3. CodeForces 97 E. Leaders(点双连通分量 + 倍增)

    题意 给你一个有 \(n\) 个点 \(m\) 条边的无向图,有 \(q\) 次询问,每次询问两个点 \(u, v\) 之间是否存在长度为奇数的简单路径. \(1 \le n, m, q \le 10 ...

  4. CF - 652 E Pursuit For Artifacts 边双联通

    题目传送门 题解总结起来其实很简单. 把所有的边双联通分量缩成一个点,然后建立好新边, 然后再从起点搜到终点就好了. 代码: /* code by: zstu wxk time: 2019/02/23 ...

  5. Pursuit For Artifacts CodeForces - 652E (Tarjan+dfs)

    Pursuit For Artifacts CodeForces - 652E Johnny is playing a well-known computer game. The game are i ...

  6. [Codeforces 555E]Case of Computer Network(Tarjan求边-双连通分量+树上差分)

    [Codeforces 555E]Case of Computer Network(Tarjan求边-双连通分量+树上差分) 题面 给出一个无向图,以及q条有向路径.问是否存在一种给边定向的方案,使得 ...

  7. codeforces 962F.simple cycle(tarjan/点双连通分量)

    题目连接:http://codeforces.com/contest/962/problem/F 题目大意是定义一个simple cycle为从一个节点开始绕环走一遍能经过simple cycle内任 ...

  8. Simple Cycles Edges CodeForces - 962F(点双连通分量)

    题意: 求出简单环的所有边,简单环即为边在一个环内 解析: 求出点双连通分量,如果一个连通分量的点数和边数相等,则为一个简单环 点双连通分量  任意两个点都至少存在两条点不重复的路径  即任意两条边都 ...

  9. POJ2942 Knights of the Round Table[点双连通分量|二分图染色|补图]

    Knights of the Round Table Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 12439   Acce ...

随机推荐

  1. 最近用到的Linux常用命令总结

    最近用到的Linux常用命令总结 - ls :显示当前目录文件信息 `ls -a -l` - cd :目录跳转 cd .. 上级目录 cd ~ home目录 cd - 最近目录 - cat :在屏幕上 ...

  2. htmlt中的块状元素与内联元素

    块元素(block element) address - 地址 blockquote - 块引用 center - 举中对齐块 dir - 目录列表 div - 常用块级容易,也是CSS layout ...

  3. CentOS安装mplayer

    据说mplayer相当于windows下的暴风影音,那么今天就来安装上mplayer. 安装的大体步骤: 安装mplayer需要安装,解码器,mplayer,皮肤. 这三个包你都可以在mplayer官 ...

  4. CentOS安装SetupTools(easy_install)

    确保Py版本在2.6或以上 (旧版本需升级或参考旧版本安装) cd /opt wget https://pypi.python.org/packages/source/s/setuptools/set ...

  5. R语言的一些笔记

    (1)包中函数必须在NAMESPACE中进行标记导出,否则就不认识了: 例如叫做rtest.Model.LogisticreRression 就能识别,而叫做Model.LogisticreRress ...

  6. Distributed R

    R语言的分布式目前有这几个产品: (A)RHadoop:对hadoop族系的产品,其中提供了以下的组件 A.1 rhdfs  浏览读取增加修改hdfs上面的文件数据: A.2 rhbase 浏览读取增 ...

  7. mirantis fuel puppet执行顺序 和 对整个项目代码的执行流程理解

    stage执行顺序 stage {'zero': } -> stage {'first': } -> stage {'openstack-custom-repo': } -> sta ...

  8. 关于vs2013 mysql Ef框架中提示版本不兼容问题的解决办法

    <runtime>     <assemblyBinding>       <dependentAssembly>         <assemblyIden ...

  9. codeforces 630K - Indivisibility

    K. Indivisibility 题意:给一个n(1 <= n <= 10^18)的区间,问区间中有多少个数不能被2~10这些数整除: 整除只需要看素数即可,只有2,3,5,7四个素数: ...

  10. zoom 用法

    from: http://www.jb51.net/css/40285.html 其实Zoom属性是IE浏览器的专有属性,Firefox等浏览器不支持.它可以设置或检索对象的缩放比例.除此之外,它还有 ...