Problem Statement

You are given a simple connected undirected graph $G$ with $N$ vertices and $M$ edges.

The vertices and edges of $G$ are numbered as vertex $1$, vertex $2$, $\ldots$, vertex $N$, and edge $1$, edge $2$, $\ldots$, edge $M$, respectively, and edge $i$ $(1\leq i\leq M)$ connects vertices $U_i$ and $V_i$.

You are also given distinct vertices $A,B,C$ on $G$.
Determine if there is a simple path connecting vertices $A$ and $C$ via vertex $B$.

What is a simple connected undirected graph?

A graph $G$ is said to be a simple connected undirected graph when $G$ is an undirected graph that is simple and connected.

A graph $G$ is said to be an undirected graph when the edges of $G$ have no direction.

A graph $G$ is simple when $G$ does not contain self-loops or multi-edges.

A graph $G$ is connected when one can travel between all vertices of $G$ via edges.

Constraints

  • $3 \leq N \leq 2\times 10^5$
  • $N-1\leq M\leq\min\left(\frac{N(N-1)}{2},2\times 10^5\right)$
  • $1\leq A,B,C\leq N$
  • $A$, $B$, and $C$ are all distinct.
  • $1\leq U_i<V_i\leq N$
  • The pairs $(U_i,V_i)$ are all distinct.
  • All input values are integers.

点不能重复,考虑圆方树。

如果 \(A,B,C\) 在一个点双内,那么一定没问题。因为删掉B 这个点一定还有路径可以到 \(C\)

那么在圆方树上的体现就是 A,B,C 连着同一个方点。

以此类推,如果 \(A,C\) 在圆方树上的路径通过了一个 B 所连的方点,那么就可以,否则割点不能重复走,所以不行。

#include<bits/stdc++.h>
using namespace std;
const int N=4e5+5;
int n,m,a,b,c,vs[N],st[N],tp,idx,dfn[N],low[N];
struct graph{
int hd[N],e_num;
struct edge{
int v,nxt;
}e[N<<1];
void add_edge(int u,int v)
{
e[++e_num]=(edge){v,hd[u]};
hd[u]=e_num;
e[++e_num]=(edge){u,hd[v]};
hd[v]=e_num;
}
}g,h;
int read()
{
int s=0;
char ch=getchar();
while(ch<'0'||ch>'9')
ch=getchar();
while(ch>='0'&&ch<='9')
s=s*10+ch-48,ch=getchar();
return s;
}
void tarjan(int x)
{
dfn[x]=low[x]=++idx;
st[++tp]=x;
for(int i=g.hd[x];i;i=g.e[i].nxt)
{
int v=g.e[i].v;
if(!dfn[v])
{
tarjan(v);
low[x]=min(low[x],low[v]);
if(low[v]==dfn[x])
{
++n;
while(st[tp]^v)
h.add_edge(n,st[tp--]);
h.add_edge(n,st[tp--]);
h.add_edge(x,n);
}
}
else
low[x]=min(low[x],dfn[v]);
}
}
void dfs(int x,int y)
{
st[++tp]=x;
if(x==c)
{
for(int i=1;i<=tp;i++)
vs[st[i]]=1;
return;
}
for(int i=h.hd[x];i;i=h.e[i].nxt)
if(h.e[i].v^y)
dfs(h.e[i].v,x);
--tp;
}
int main()
{
n=read(),m=read(),a=read(),b=read(),c=read();
for(int i=1,u,v;i<=m;i++)
g.add_edge(read(),read());
tarjan(a);
dfs(a,0);
for(int i=h.hd[b];i;i=h.e[i].nxt)
if(vs[h.e[i].v])
return puts("Yes"),0;
puts("No");
}

[ABC318G] Typical Path Problem的更多相关文章

  1. Eclipse 项目红色叹号:Build Path Problem

    Description Resource Path Location TypeA cycle was detected in the build path of project 'shgl-categ ...

  2. Solve Longest Path Problem in linear time

    We know that the longest path problem for general case belongs to the NP-hard category, so there is ...

  3. Why longest path problem doesn't have optimal substructure?

    We all know that the shortest path problem has optimal substructure. The reasoning is like below: Su ...

  4. Codefroces Educational Round 27 845G Shortest Path Problem?

    Shortest Path Problem? You are given an undirected graph with weighted edges. The length of some pat ...

  5. 干货 | 列生成VRPTW子问题ESPPRC( Elementary shortest path problem with resource constraints)介绍附C++代码

    00 前言 各位小伙伴大家好,相信大家已经看过前面column generation求解vehicle routing problems的过程详解.该问题中,子问题主要是找到一条reduced cos ...

  6. 安装数据库Typical path for xclock: /usr/X11R6/bin/xclock 错误问题

    [oracle@localhost database]$ ./runInstaller Starting Oracle Universal Installer... Checking Temp spa ...

  7. [BFS,A*,k短路径] 2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛 path (Problem - 6705)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=6705 path Time Limit: 2000/2000 MS (Java/Others)    Mem ...

  8. 【CF edu 27 G. Shortest Path Problem?】

    time limit per test 3 seconds memory limit per test 512 megabytes input standard input output standa ...

  9. Codeforces 845G Shortest Path Problem?

    http://codeforces.com/problemset/problem/845/G 从顶点1dfs全图,遇到环则增加一种备选方案,环上的环不需要走到前一个环上作为条件,因为走完第二个环可以从 ...

  10. Project 'king.commons' is missing required library: 'lib/plweb.jar' Build path Build Path Problem

    问题描述:之前在项目里引用一个jar 包,后来不用了删掉 ,但是没有删干净,然后报以下错误. 解决方案: 1.删除libraries 2.找到该项目下的 .classpath 文件,用记事本打开 ,删 ...

随机推荐

  1. CentOS7.9中的Glibc2.17源码编译升级到Glibc2.31

    一.准备工作 1.配置yum阿里镜像源 查看yum当前配置的仓库,如果yum配置的不是阿里云源,请配置阿里云源. yum repolist all 验证是否能ping通阿里云 # 如果不能ping通可 ...

  2. ubuntu/linux 好用的截图工具 搜狗输入法自带的截图快捷键,自己觉得不方便的话,修改为自己习惯的快捷键即可

    公司要求使用ubuntu开发,在安装完必要得开发工具之后,按照我在windows平台的习惯,就准备安装一个好用的截图工具了,我比较推荐的是snipaste([https://zh.snipaste.c ...

  3. WPF-封装自定义雷达图控件

    源码地址:https://gitee.com/LiuShuiRuoBing/code_blog 雷达图用于表示不同内容的占比关系,在项目中有广泛的应用,但是目前未曾有封装良好的雷达图控件,鉴于最近项目 ...

  4. 获得lazada商品详情 API 返回值说明

    ​ item_get-获得lazada商品详情 注册开通 lazada.item_get 公共参数 名称 类型 必须 描述 key String 是 调用key(必须以GET方式拼接在URL中) se ...

  5. 《Python魔法大冒险》007 被困的精灵:数据类型的解救

    小鱼和魔法师深入魔法森林,树木之间流淌着神秘的光芒,每一片叶子都似乎在低语着古老的咒语.不久,他们来到了一个小湖旁,湖中央有一个小岛,岛上困着一个透明的泡泡,里面有一个悲伤的精灵. 小鱼看着那个精灵, ...

  6. ModbusTCP 转 Profinet 主站网关在博图配置案例

    ModbusTCP 转 Profinet 主站网关在博图配置案例 兴达易控ModbusTCP转Profinet网关,在 Profinet 侧做为 Profinet 主站控制器,接 Profinet 设 ...

  7. selenium库浅析

    selenium库浅析 基于4.3 pip install selenium安装好后,在sitepackages下 2个主要的目录,common和webdriver 1- common 该目录一共就一 ...

  8. 2023-09-23:用go语言,假设每一次获得随机数的时候,这个数字大于100的概率是P。 尝试N次,其中大于100的次数在A次~B次之间的概率是多少? 0 < P < 1, P是double类型,

    2023-09-23:用go语言,假设每一次获得随机数的时候,这个数字大于100的概率是P. 尝试N次,其中大于100的次数在A次~B次之间的概率是多少? 0 < P < 1, P是dou ...

  9. vue中watch侦听器,deep和immediate的用法

    1.deep深度监听的用法 当监听一个对象时,可能想监听整个对象的变化,而不仅仅是某个属性.但在默认情况下,如果你正在监听formData对象并且修改了formData.username,对应的侦听器 ...

  10. linux常用命令(七)

    用于系统内信息交流的相关命令 echo mesg wall write echo:在显示器上显示文字 命令语法:echo[选项] [字符串] 选项 选项含义 -n 表示输出文字后不换行 例子:将文本& ...