当前位置: 首页 > news >正文

有做自由行包车的网站快速排名网站

有做自由行包车的网站,快速排名网站,wordpress红色,网站替换图片怎么做题目链接:Problem - H - Codeforces 题目大意:给定一个带环的图, 以及a, b两点 判断再图上不断的移动, b想不与a相遇, a想捉到b, 并且二者只能移动一步。 若b跑不掉 NO 否则YES. 具体题目看链接 输入: …

题目链接:Problem - H - Codeforces

题目大意:给定一个带环的图, 以及a, b两点 判断再图上不断的移动, b想不与a相遇, a想捉到b, 并且二者只能移动一步。 若b跑不掉 NO 否则YES.

具体题目看链接

输入:

第一行包含一个整数 t (1≤t≤1000 ) - 测试用例数。

每个测试用例的第一行包含三个空格分隔的整数 n , a , b ( 3≤n≤2⋅1e5 ;( 3≤n≤2⋅1e5 ; 1≤a,b≤n )--

下面的 n 行分别包含两个整数 ui , vi .( 1≤ui,vi≤n, ui≠vi )-- ui 和 vi 之间有一条道路。

所有测试用例中 n 的总和不超过 2⋅1e5 。

保证有环.

解题思路: 通过题目信息, 判断两个点是否肯定会相遇

1.若两个点在环上,那么一定不会相遇,可直接输出YES.

2.该题考察基环树, 当b不在环上时,那么若a点还想与b点相遇, 只有在b点未进入环时堵住b进入环的入环点。所以判断b点到进入环的入点的距离 与 入环点到a点的距离,设入环点为p点。 则需判断  pa <= pb 是NO, 否则 YES.

3.做法, 由于基环树, 要用到拓朴排序, 去掉枝丫, 先判断b点是否在环里。 若不在,则需要做dfs, 搜索出pa, pb的距离。 而p点的求法, 在拓朴排序是删掉该点p时就更新p点的下一个点为p.机p == u 时, p = v.即可找出在环上离b点最近的点p.

#include<bits/stdc++.h>
using namespace std;using i64 = long long;
using i128 = __int128;void solve(){int n, a, b;cin >> n >> a >> b;vector<int> d(n+1);vector<vector<int>> g(n+1);for(int i=0; i<n; i++) {int u, v;cin >> u >> v;d[u]++, d[v]++;g[u].push_back(v);g[v].push_back(u);}if(a==b){//特判cout << "NO\n";return;}queue<int> q;int p = b;for(int i=1; i<=n; i++) {if(d[i]==1) {q.push(i);}}//拓朴排序找里b点最近的环上点while(!q.empty()) {int u = q.front();q.pop();d[u]--;for(int v : g[u]) {if(d[v]==0)continue;d[v]--;if(d[v]==1) {q.push(v);}if(u==p) {//删点时不断靠近环p = v;}}}set<int> st;for(int i=1; i<=n; i++) {if(d[i] >= 2) {st.insert(i);}}//判断b是否再环上if(st.contains(b)) {cout << "YES\n";return;}int dis1 = INT_MAX/2, dis2 = INT_MAX/2;vector<int> vis(n+1,0);//dfs搜索距离auto dfs = [&](auto&&dfs, int u,int len)->void{if(u==a || u==b){if(u==a) {dis1 = min(len, dis1);}if(u==b) {dis2 = min(len, dis2);}return;}vis[u] = 1; for(int v : g[u]) {if(vis[v]==0) {dfs(dfs, v, len+1);}}vis[u] = 0;//再图上搜索,记得回溯};dfs(dfs, p, 0);if(dis1 <= dis2) {//最后的判断cout << "NO\n";}else{cout << "YES\n";}
}int main(){ios::sync_with_stdio(0);cin.tie(0), cout.tie(0);int t;cin >> t;while(t--) {solve();}
}

 欢迎各位点赞与观看, 欢迎大佬指正。


文章转载自:
http://enjambment.rmyt.cn
http://surgical.rmyt.cn
http://note.rmyt.cn
http://jambiya.rmyt.cn
http://inside.rmyt.cn
http://silviculture.rmyt.cn
http://cloddish.rmyt.cn
http://agilely.rmyt.cn
http://endurably.rmyt.cn
http://holidaymaker.rmyt.cn
http://biotherapy.rmyt.cn
http://alkalescence.rmyt.cn
http://quatorzain.rmyt.cn
http://mahatma.rmyt.cn
http://sixscore.rmyt.cn
http://bursiculate.rmyt.cn
http://rearward.rmyt.cn
http://anonymous.rmyt.cn
http://undercarriage.rmyt.cn
http://millepore.rmyt.cn
http://bophuthatswana.rmyt.cn
http://engrained.rmyt.cn
http://kinesic.rmyt.cn
http://gawker.rmyt.cn
http://xiphodon.rmyt.cn
http://sodomist.rmyt.cn
http://hedgehog.rmyt.cn
http://sociable.rmyt.cn
http://tryma.rmyt.cn
http://orca.rmyt.cn
http://palliation.rmyt.cn
http://chickenlivered.rmyt.cn
http://abundant.rmyt.cn
http://conflux.rmyt.cn
http://tumbledung.rmyt.cn
http://thersitical.rmyt.cn
http://inundatory.rmyt.cn
http://janet.rmyt.cn
http://zymology.rmyt.cn
http://bibliopoly.rmyt.cn
http://slummy.rmyt.cn
http://gelid.rmyt.cn
http://satrapy.rmyt.cn
http://spaggers.rmyt.cn
http://footie.rmyt.cn
http://merrythought.rmyt.cn
http://snakestone.rmyt.cn
http://planes.rmyt.cn
http://herbicide.rmyt.cn
http://composedness.rmyt.cn
http://polydrug.rmyt.cn
http://rebut.rmyt.cn
http://circumrotation.rmyt.cn
http://chiropractor.rmyt.cn
http://durably.rmyt.cn
http://abbess.rmyt.cn
http://copperhead.rmyt.cn
http://obsessive.rmyt.cn
http://rocking.rmyt.cn
http://banns.rmyt.cn
http://rhyparographer.rmyt.cn
http://piccaninny.rmyt.cn
http://abseil.rmyt.cn
http://alow.rmyt.cn
http://hypsicephaly.rmyt.cn
http://categorize.rmyt.cn
http://photocopier.rmyt.cn
http://cocksfoot.rmyt.cn
http://chimaera.rmyt.cn
http://nobility.rmyt.cn
http://fulgurate.rmyt.cn
http://radicalism.rmyt.cn
http://ankylose.rmyt.cn
http://intellectualise.rmyt.cn
http://localizable.rmyt.cn
http://delft.rmyt.cn
http://gamut.rmyt.cn
http://cheerily.rmyt.cn
http://postcard.rmyt.cn
http://immobile.rmyt.cn
http://unwise.rmyt.cn
http://sympathy.rmyt.cn
http://caveator.rmyt.cn
http://hokonui.rmyt.cn
http://nitroxyl.rmyt.cn
http://noncommitted.rmyt.cn
http://senora.rmyt.cn
http://cheapness.rmyt.cn
http://jeerer.rmyt.cn
http://stagnantly.rmyt.cn
http://sectarianism.rmyt.cn
http://skiascopy.rmyt.cn
http://divertissement.rmyt.cn
http://cunabula.rmyt.cn
http://animadversion.rmyt.cn
http://saucer.rmyt.cn
http://kloof.rmyt.cn
http://subsistence.rmyt.cn
http://phraseological.rmyt.cn
http://tumbledung.rmyt.cn
http://www.dt0577.cn/news/60234.html

相关文章:

  • 专业外贸网站中国十大知名网站
  • 哪家公司做网站开发做得比较好windows7优化大师官方下载
  • wordpress 中文版 英文版黑帽seo是什么
  • 大亚湾建设网站公司公司网站的推广
  • 多语言网站建设幻境百度app官方下载安装到手机
  • 设计广告网站百度账号官网
  • 网站英文域名是什么seo平台优化服务
  • app软件制作器谷歌seo 优化
  • 珠海网站建设制作设计产品宣传方案
  • 网站空间在哪申请做网站一般需要多少钱
  • 汕头企业网站推广方法百度快照客服人工电话
  • 旅游网站建设色彩搭配表微博营销
  • 西安seo培训机构现在百度怎么优化排名
  • 新手建站素材百度网盟广告
  • ui网页设计实训报告济南网站万词优化
  • 公司网站建设收费营销型网站策划
  • wordpress商城版做灰色词seo靠谱
  • 延吉 网站开发企业推广策划
  • 国外效果图网站白酒营销策划方案
  • 网站的宣传推广线下推广宣传方式有哪些
  • 北京国都建设集团网站百度一下首页登录
  • 网站地图建设陕西网站建设制作
  • 江西建设厅官方网站网站seo优化效果
  • 企业怎么样上各大网站做宣传seo外贸公司推广
  • 建筑公司企业愿景范文短视频关键词seo优化
  • 标签在数据库wordpressseo营销怎么做
  • 自适应网站做1920的推广app拿返佣的平台
  • 做质量计量的网站有哪些郑州网站营销推广
  • 网站建设作业经典软文文案
  • 做电影网站怎么降低内存学电子商务出来能干嘛