Codeforces Round #606 E
题:https://codeforces.com/contest/1277/problem/E
题意:给定无向图,求有多少个pair之间的简单路径一定要经过给定的点a和b(pair中任何一个都不是a或b)
分析:分别从俩个点开始dfs ,以从a为起点为例,每次若dfs到了b,我们可以想象,剩余没遍历到的点一定是与这些点不联通的,也就是相当于a的其余子树。得解
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pi pair<int,int>
typedef long long ll;
const int inf=0x3f3f3f3f;
const ll INF=1e18;
const int M=1e6+;
const int mod=1e9+;
vector<int>g[M];
int vis[M];
int flag;
ll nowsum;
void dfs(int u,int sign){
nowsum++;
vis[u]=;
if(u==sign)
flag=;
for(auto v:g[u]){
if(!vis[v])
dfs(v,sign);
}
}
int main(){
int t;
scanf("%d",&t);
while(t--){
int n,m,a,b;
scanf("%d%d%d%d",&n,&m,&a,&b);
for(int i=;i<=n;i++)
vis[i]=,g[i].clear();
while(m--){
int u,v;
scanf("%d%d",&u,&v);
g[u].pb(v);
g[v].pb(u);
}
flag=;
ll suma=,sumb=;
vis[a]=;
for(auto v:g[a]){
nowsum=;
dfs(v,b);
if(flag){
suma=1ll*(n-nowsum-);
break;
}
}
// cout<<suma<<endl;
flag=; for(int i=;i<=n;i++)
vis[i]=;
vis[b]=;
for(auto v:g[b]){
nowsum=;
dfs(v,a);
if(flag){
sumb=1ll*(n-nowsum-);
break;
}
}
printf("%I64d\n",suma*sumb);
}
return ;
}
Codeforces Round #606 E的更多相关文章
- Codeforces Round #606(B-D)
Dashboard - Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4) - Codeforces ...
- 【cf比赛记录】Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4)
比赛传送门 只能说当晚状态不佳吧,有点头疼感冒的症状.也跟脑子没转过来有关系,A题最后一步爆搜没能立即想出来,B题搜索没有用好STL,C题也因为前面两题弄崩了心态,最后,果然掉分了. A:简单数学 B ...
- 20191214 Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4)
概述 切了 ABCE,Room83 第一 还行吧 A - Happy Birthday, Polycarp! 题解 显然这样的数不会很多. 于是可以通过构造法,直接求出 \([1,10^9]\) 内所 ...
- Codeforces Round #606 (Div. 2)
传送门 A. Happy Birthday, Polycarp! 签到. Code /* * Author: heyuhhh * Created Time: 2019/12/14 19:07:57 * ...
- Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4)
链接 签到题,求出位数,然后9*(位数-1)+ 从位数相同的全一开始加看能加几次的个数 #include<bits/stdc++.h> using namespace std; int m ...
- Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4) 题解
Happy Birthday, Polycarp! Make Them Odd As Simple as One and Two Let's Play the Words? Two Fairs Bea ...
- Codeforces Round #606 (Div. 1) Solution
从这里开始 比赛目录 我菜爆了. Problem A As Simple as One and Two 我会 AC 自动机上 dp. one 和 two 删掉中间的字符,twone 删掉中间的 o. ...
- Codeforces Round #606 (Div. 2) E - Two Fairs(DFS,反向思维)
- Codeforces Round #606 (Div. 2) D - Let's Play the Words?(贪心+map)
随机推荐
- C++基础--string转
有时候除了要将数值型转为string外,可能也需要将一些string转为数值型,这个时候也还是可以用sstream字符串流来实现,同时也可以用C++标准库得到函数来实现. 1.字符串流 这个时候使用i ...
- Hibernate(八)--session的两种获取方式
openSession getCurrentSession Hibernate有两种方式获得session,分别是: openSession和getCurrentSession他们的区别在于1. 获取 ...
- .Net实现发送邮件功能
public ActionResult AddPost() { ResponseResult result = new ResponseResult(); ...
- Short Essay你真的会写了吗?
提到short essay(可能其他essay也一样),很多同学都很头疼.“没有思路?不知从何下笔?没有亮点?”等等,这些都是同学们的致命伤,因此,short essay就成为了广大留学生的“送命题” ...
- 吴裕雄--天生自然 PHP开发学习:数据类型
<?php $x = "Hello world!"; echo $x; echo "<br>"; $x = 'Hello world!'; e ...
- Java基础——HashTable源码分析
HashTable是基于哈希表的Map接口的同步实现 HashTable中元素的key是唯一的,value值可重复 HashTable中元素的key和value不允许为null,如果遇到null,则返 ...
- 学习spring的第二天
对昨天的查漏:关于<bean>标签的scope属性,是由它决定原型和单例的,而不是说你java代码中用到了单例模式就是单例了. 其二就是lazy-init属性,它对于scope=" ...
- Mdb文件工具类,UCanAccess使用,Access数据库操作
================================ ©Copyright 蕃薯耀 2020-01-09 https://www.cnblogs.com/fanshuyao/ 使用Ocbc ...
- 吴裕雄--天生自然 JAVASCRIPT开发学习: JSON
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- SQL基础教程(第2版)第4章 数据更新:练习题
行也选取不出来. >> 解答 A 先生使用 BEGIN TRANSACTION 启动了事务处理,然后开始执行 INSERT 语句.因此,在 A 先生使用 COMMIT 确定该更新之前, B ...