[ABC318G] Typical Path Problem
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的更多相关文章
- Eclipse 项目红色叹号:Build Path Problem
Description Resource Path Location TypeA cycle was detected in the build path of project 'shgl-categ ...
- 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 ...
- 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 ...
- 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 ...
- 干货 | 列生成VRPTW子问题ESPPRC( Elementary shortest path problem with resource constraints)介绍附C++代码
00 前言 各位小伙伴大家好,相信大家已经看过前面column generation求解vehicle routing problems的过程详解.该问题中,子问题主要是找到一条reduced cos ...
- 安装数据库Typical path for xclock: /usr/X11R6/bin/xclock 错误问题
[oracle@localhost database]$ ./runInstaller Starting Oracle Universal Installer... Checking Temp spa ...
- [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 ...
- 【CF edu 27 G. Shortest Path Problem?】
time limit per test 3 seconds memory limit per test 512 megabytes input standard input output standa ...
- Codeforces 845G Shortest Path Problem?
http://codeforces.com/problemset/problem/845/G 从顶点1dfs全图,遇到环则增加一种备选方案,环上的环不需要走到前一个环上作为条件,因为走完第二个环可以从 ...
- Project 'king.commons' is missing required library: 'lib/plweb.jar' Build path Build Path Problem
问题描述:之前在项目里引用一个jar 包,后来不用了删掉 ,但是没有删干净,然后报以下错误. 解决方案: 1.删除libraries 2.找到该项目下的 .classpath 文件,用记事本打开 ,删 ...
随机推荐
- 数据api接口就是应用集成吗?
数据 API 接口和应用集成是两个不同的概念,但是它们之间有一定的联系.数据 API 接口是一种用于访问和传输数据的标准化接口,而应用集成则是将不同的应用程序和系统整合在一起,实现数据和业务流程的 ...
- C#结合OpenCVSharp4使用直方图算法比较图片相似度
C#结合OpenCVSharp4使用直方图算法比较图片相似度 直方图有灰度直方图.颜色直方图,如果是灰度图像,那么就用灰度直方图,这里使用颜色直方图来计算两个图片的相似度. 这里只记录如何使用,至于算 ...
- 了解JAVA内存模型(JMM)
1.概述 我们常说的JMM指的是Java内存模型(Java Memory Model,JMM),主要用于控制Java程序解决线程间如何通信和数据同步,JMM规范了多线程访问共享内存时的 可见性.有序性 ...
- SSM-Mybatis笔记
目录 Mybatis-9.28 1.简介 1.1.什么是Mybatis 1.2.持久化 1.3.持久层 1.4 为什么需要Mybatis? 2.第一个Mybatis程序 2.1.搭建环境 2.2.创建 ...
- 低代码引擎 TinyEngine 正式发布!
在当今数字化飞速发展的时代,企业对高效.敏捷的应用程序需求日益旺盛.为了满足这一需求,越来越多的低代码开发平台开始涌现.这些平台通过提供简单易用的开发工具和优化后的开发流程,帮助开发者快速构建高质量. ...
- 实战指南,SpringBoot + Mybatis 如何对接多数据源
本文分享自华为云社区 <实战指南,SpringBoot + Mybatis 如何对接多数据源>,作者:战斧. 在我们开发一些具有综合功能的项目时,往往会碰到一种情况,需要同时连接多个数据库 ...
- Django框架——模板层
文章目录 1 模板层 一 模版简介 二 模版语法之变量 views.py html文件 三 模版之过滤器 语法: default length filesizeformat date slice tr ...
- Python基础——深浅拷贝、python内存泄露、你并不了解的format、decimal
文章目录 深浅拷贝 先看赋值运算 浅拷贝copy 深拷贝deepcopy 相关面试题 python内存泄露 起因 方案 编写安全的代码 弱引用 你并不了解的format.decimal format格 ...
- Go函数介绍与一等公民
Go函数介绍与一等公民 函数对应的英文单词是 Function,Function 这个单词原本是功能.职责的意思.编程语言使用 Function 这个单词,表示将一个大问题分解后而形成的.若干具有特定 ...
- 【数字图像处理】Matlab实现-图像增强-彩色图像增强(彩虹编码,热金属编码)
伪彩色处理 伪彩色增强:把一幅黑白域图像的不同灰度级映射为一幅彩色图像的技术手段. 伪彩色增强有很多种方法,而下面的增强方法则是使用的空间域灰度级-彩色变换法. 空间域灰度级-彩色变换法:可以将灰度图 ...