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)
随机推荐
- DNS bind9安装
参考 111 首先要成功安装Centos操作系统,最新版本是Centos 6.4版本,最小化安装. [root@localhost named]# ifconfig -a 0 1 eth1 ...
- 自学Java第五章——《面向对象基础》
5.1 类与对象 1.类:一类具有相同特性的事物的抽象描述. 对象:类的一个个体,实例,具体的存在. 类是对象的设计模板. 2.如何声明类? [修饰符] class 类名{ 成员列表:属性.方法 ...
- java课程之团队开发第一阶段评论
1.没有UI设计,整体的样式感觉不堪入目 2.功能方面实现的并不是很多,还需要继续努力 3.还需要添加一些常用的课表功能,比如说导入课表等
- Python 中异常嵌套
在Python中,异常也可以嵌套,当内层代码出现异常时,指定异常类型与实际类型不符时,则向外传,如果与外面的指定类型符合,则异常被处理,直至最外层,运用默认处理方法进行处理,即停止程序,并抛出异常信息 ...
- NumPy - 数组(定义,拼接)
NumPy 教程(数组) set_printoptions(threshold='nan') NumPy的数组中比较重要ndarray对象属性有: ndarray.ndim:数组的维数(即数组轴的个数 ...
- Kettle无法下载以及点击无反应的问题
最开始用于解决MySQL转移数据到ORACLE的问题,尝试了几种方法. 1.直接从Mysql导出csv文件.这种方式最直接简单,但是问题是数据大的话,容易出现数据对不齐的情况,导入这个时候就会出现错误 ...
- Win10 MySQL5.7中文乱码问题
https://blog.csdn.net/hh___56789/article/details/87900923 最好把 utf8 都换成utf8mb4 ,以免以后遇到意想不到的错误.utf8有漏洞 ...
- {转} MJPG流媒体在HTML5的呈现方案
最近碰到的需求:监控探头视频呈现到html页面上. 视频源协议:HLS; 视频源格式:Motion JPEG 简称 MJPG; 其中Motion JPEG(M-JPEG或MJPEG,Motion Jo ...
- offset系列、client系列、scroll系列
offset系列.client系列 <style> .testDOM { width: 200px; height: 200px; background-color: #2de; pa ...
- 翻译——3_Gaussian Process Regression
使用不同的机器学习方法进行预测 续上篇2_Linear Regression and Support Vector Regression 高斯过程回归 %matplotlib inline impor ...