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)
随机推荐
- css ~ a标签占满父级元素
width: 100%; height: 100%; display: block;
- pppd调试心得.md
描述 pppd是用于驱动3g模块的一种方式,其本质是和运营商APN协商,建立连接 其与运营商之间使用ppp协议,而用户在应用层使用系统提供的socket即可,从而忽略底层使用的时何种接口的设备,避免因 ...
- s5pc100开发板linux内核移植
相关软件下载地址:http://pan.baidu.com/s/16yo8Y 应用于FSC100开发板 交叉编译工具:arm-cortex_a8-linux-gnueabi-gcc linux-2.6 ...
- java课程课后作业190616之个人学期总结
在团队开始的那一周,我们做了作品的功能畅想,在讲台上谈论了自己的产品可能会有的功能,比如说课程查找功能,空教室查找功能,霸屏功能,课程留言功能等,当然,随着开发的推进,我也发现了有些功能上实现的困难, ...
- bugku-Web-多次(异或注入,判断被过滤的关键字)
进去看到url感觉是sql注入, 加上',报错但是%23不报错,加上'--+,也不报错,说明可以用--+注释 加上' or 1=1--+,报错 尝试' oorr 1=1--+,正常 说明or被过滤了. ...
- 吴裕雄--天生自然JAVA SPRING框架开发学习笔记:Spring Bean的生命周期
Spring 容器可以管理 singleton 作用域 Bean 的生命周期,在此作用域下,Spring 能够精确地知道该 Bean 何时被创建,何时初始化完成,以及何时被销毁. 而对于 protot ...
- c 循环左移
char b[11] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'}; const int iShift = 4; for (int j = ...
- 使用connected-react-router使router与store同步
connected-react-router是一个绑定react-router到redux的组件,来实现双向绑定router的数据到redux store中,这么做的好处就是让应用更Redux化,可以 ...
- MSE(均方误差)、RMSE (均方根误差)、MAE (平均绝对误差)
1.MSE(均方误差)(Mean Square Error) MSE是真实值与预测值的差值的平方然后求和平均. 范围[0,+∞),当预测值与真实值完全相同时为0,误差越大,该值越大. import n ...
- HCTF2018-admin
记录一道比较有意思的题目,对于萌新来说能学到很多东西orz.. 三种解法: 1: flask session 伪造 2: unicode欺骗 3: 条件竞争 注册账户查看源码: 发现提示,根据提示和题 ...