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)
随机推荐
- jquery - 导航轮播图
1,slider.js /** * slider插件可悬停控制 */ ; $(function ($, window, document, undefined) { Slider = functi ...
- 19 01 15 js 尺寸相关 滚动事件
尺寸相关.滚动事件 1.获取和设置元素的尺寸 width().height() 获取元素width和height innerWidth().innerHeight() 包括padding的width和 ...
- Day3-T4
原题目 Describe:有点恶心的DP+最短路 code: #include<bits/stdc++.h> using namespace std; long long A,B,C,z, ...
- Java平台上的AOP实现机制
Java平台上的AOP实现机制 动态代理(Dynamic Proxy)机制,在运行期间动态的为相应接口生成对应的代理对象.SpringAop默认情况下采用这种机制来实现AOP机能.缺点:相对于编译后的 ...
- 第二阶段scrum-3
1.整个团队的任务量: 2.任务看板: 会议照片: 产品状态: 前端制作完成,数据库正在配置
- 关于GAN的一些笔记
目录 1 Divergence 1.1 Kullback–Leibler divergence 1.2 Jensen–Shannon divergence 1.3 Wasserstein distan ...
- mysql数值类型总结及常用函数
最近在学习下,总结一下mysql数值类型: mysql字符类型分: 1.整数类型: 字节 值范围 INTERGER 1 ...
- C++逐行读取txt
C++读取txt文件的时候可以使用std::ifstream来实现,如果打开文件失败的话,其变量会是空的,所以可以用来判断是否打开成功. #include <stdlib.h> #in ...
- Java 类提供了自定义的构造方法,那么类的默认构造不会被调用
以下代码无法通过编译: public class Test1 { public static void main(String[] args) { //int a=6; Foo obj=new Foo ...
- nodejs(15)express开启cors跨域
express开启cors跨域 package.json "dependencies": { "body-parser": "^1.18.3" ...