题意: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. 51nod1046快速幂取余

    给出3个正整数A B C,求A^B Mod C.   例如,3 5 8,3^5 Mod 8 = 3. Input 3个正整数A B C,中间用空格分隔.(1 <= A,B,C <= 10^ ...

  2. OpenDialog获取文件名

    //OpenDialog获取文件 procedure TForm2.Button1Click(Sender: TObject); begin File_Path:=''; if OpenDialog1 ...

  3. Android开发第1篇 - Android开发环境搭建

    归结一下,需要进行Android开发所需要的工具或软件: Eclipse - Android是基于JAVA的开发,所以选用目前来说使用较高的Eclipse作为IDE. ADT (Android Dev ...

  4. 常用后台frame框架

    一般后台框架结构: top:左边显示logo,右边显示模块信息. left:对应模块的菜单信息. content:具体的内容. bottom:版权.时间等一些碎屑信息. Html代码: <htm ...

  5. objective-c常用数学方法

    1. 三角函数  double sin (double);正弦  double cos (double);余弦  double tan (double);正切  2 .反三角函数  double as ...

  6. CATransition的动画效果类型及实现方法--老代码备用参考

    实现iphone漂亮的动画效果主要有两种方法,一种是UIView层面的,一种是使用CATransition进行更低层次的控制, 第一种是UIView,UIView方式可能在低层也是使用CATransi ...

  7. oracle 内置函数 least decode

    在博客园的第一个博客,为什么叫第一个.... oracle 内置函数 east(1,2,3,4.....) 可以有多个值,最多几个?不知道欢迎补充 ,,,) from dual 这个函数返回是1,就是 ...

  8. 几个.net的GUI控件库

    https://github.com/firstfloorsoftware/mui http://wpftoolkit.codeplex.com/ https://github.com/fluentr ...

  9. this、call和apply

    this call apply this 和其他语言不同,JavaScript的this总是指向一个对象,而具体指向哪个对象是在运行时基于函数的执行环境动态绑定的,而非函数被声明时的环境. this的 ...

  10. Welcome

    唔.你好! 这里是 Evensgn 的笔记本. 我是 SD 省的一名高中 OIer,从初中就接触了 OI ,然而水平一直是弱弱哒. Evensgn 是我常用的 ID. 不忘初心,方能始终. E-mai ...