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. 《SQL与数据库基础》15. 触发器

    目录 触发器 语法 示例-insert型触发器 示例-update型触发器 示例-delete型触发器 本文以 MySQL 为例 触发器 触发器是与表有关的数据库对象,指在 insert/update ...

  2. hihocoder offer收割赛。。#1284

    好久没刷题,水一水,反正排不上名次..这道题记下 我想着蛋疼的做了质因数分解,然后再算的因子个数..慢的一比,结果导致超时,还不如直接一个for循环搞定..也是醉了 最后其实就是算两个数的gcd,然后 ...

  3. 面霸的自我修养:ThreadLocal专题

    王有志,一个分享硬核Java技术的互金摸鱼侠 加入Java人的提桶跑路群:共同富裕的Java人 今天是<面霸的自我修养>第5篇文章,我们一起来看看面试中会问到哪些关于ThreadLocal ...

  4. LeetCode279:完全平方数,动态规划解法超过46%,作弊解法却超过97%

    欢迎访问我的GitHub 这里分类和汇总了欣宸的全部原创(含配套源码):https://github.com/zq2599/blog_demos 本篇概览 本篇概览 这是道高频面试题,值得一看 首先, ...

  5. 试试用Markdown来设计表单

    相信很多后端开发.对于前端知识是比较零碎的,所以很多时候写表单这样的工作,一般就是复制黏贴,然后改改字段.对于HTML格式,一直觉得比较杂乱,不够简洁. 最近TJ发现了一个有趣的小工具:Create ...

  6. Visual Studio必备插件

    1.Rainbow Braces 2.Codist 3.ResXManager 4.XAML Styler for Visual Studio 2022 5.Viasfora 6.ZenCoding ...

  7. Go 语言的前生今世与介绍

    Go 语言的前生今世与介绍 目录 Go 语言的前生今世与介绍 一. Go 语言的发展 1.1 Go 语言是如何诞生的? 1.2 Go语言的早期团队和演进历程 1.3 Go语言正式发布并开源 1.4 G ...

  8. k8s集群部署初体验

    目录 ██ 环境准备[所有节点] ██ 安装Docker/kubeadm/kubelet[所有节点] ██ 部署 k8s master ██ 部署 k8s node ██ 部署网络插件[CNI] ██ ...

  9. 【图像处理】如何使用matplotlib 库显示灰度图像为自定义颜色

    项目场景 我这里有一张名为airplane.jpg的灰度图像灰度图像 使用 matplotlib 库读取并显示: import matplotlib.pyplot as plt root=" ...

  10. Android dumpsys介绍

    目录 一.需求 二.环境 三.相关概念 3.1 dumpsys 3.2 Binder 3.3 管道 四.dumpsys指令的使用 4.1 dumpsys使用 4.2 dumpsys指令语法 五.详细设 ...