【Codeforces Round #482 (Div. 2) C】Kuro and Walking Route
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
把x..y这条路径上的点标记一下。
然后从x开始dfs,要求不能走到那些标记过的点上。记录节点个数为cnt1(包括x)
然后从y开始dfs,也要求不能走到那些标记过的点上。记录节点个数为cnt2(包括y)
答案就为n(n-1)-cnt1cnt2;
(即所有的点对减去这些不符合要求的点对
【代码】
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define inf 0x3f3f3f3f
#define pll pair<ll,ll>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rep1(i,a,b) for(int i=a;i>=b;i--)
#define rson rt<<1|1,m+1,r
#define lson rt<<1,l,m
using namespace std;
const int N=3e5+100;
vector<int>G[N];
int vis[N];
int have,n,x,y;
int Pre[N+10];
int bo[N+10];
long long cnt[2];
void fx(int X,int pre){
int len = G[X].size();
for (int Y:G[X]){
if (Y==pre) continue;
Pre[Y] = X;
fx(Y,X);
}
}
void dfs(int X,int pre,int index){
for (int Y:G[X]){
if (bo[Y]) continue;
if (Y==pre) continue;
cnt[index]++;
dfs(Y,X,index);
}
}
//one more try?ok
int main()
{
#ifdef LOCAL_DEFINE
freopen("F:\\program\\rush\\rush_in.txt","r",stdin);
#endif
ios::sync_with_stdio(false),cin.tie(0);
cin>>n>>x>>y;
rep(i,0,n-2)
{
int a,b;
cin>>a>>b;
G[a].pb(b);
G[b].pb(a);
}
fx(x,-1);
for (int i = y; ;i = Pre[i]){
bo[i] = true;
if (i==x) break;
}
dfs(x,-1,0);
dfs(y,-1,1);
cnt[0]++;cnt[1]++;
cout<<1LL*n*(n-1)-cnt[0]*cnt[1];
return 0;
}
【Codeforces Round #482 (Div. 2) C】Kuro and Walking Route的更多相关文章
- Codeforces Round #482 (Div. 2) C 、 Kuro and Walking Route(dfs)979C
题目链接:http://codeforces.com/contest/979/problem/C 大致题意 给出n个点,有n-1个边将他们链接.给出x,y,当某一路径中出现x....y时,此路不通.路 ...
- Codeforces Round #482 (Div. 2) :C - Kuro and Walking Route
题目连接:http://codeforces.com/contest/979/problem/C 解题心得: 题意就是给你n个点,在点集中间有n-1条边(无重边),在行走的时候不能从x点走到y点,问你 ...
- 【Codeforces Round #482 (Div. 2) B】Treasure Hunt
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 我们考虑每个字符串中出现最多的字母出现的次数cnt[3] 对于这3个cnt的值. 如果cnt+n<=s[i].size 那么显 ...
- 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers
[链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...
- 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes
[题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...
- 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees
[题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...
- 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory
[题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...
- 【Codeforces Round #423 (Div. 2) C】String Reconstruction
[Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...
- 【Codeforces Round #423 (Div. 2) B】Black Square
[Link]:http://codeforces.com/contest/828/problem/B [Description] 给你一个n*m的格子; 里面包含B和W两种颜色的格子; 让你在这个格子 ...
随机推荐
- 00064_字符串缓冲区_StringBuffer类
1.StringBuffer类 (1)StringBuffer又称为可变字符序列,它是一个类似于 String 的字符串缓冲区,通过某些方法调用可以改变该序列的长度和内容. (2)tringBuffe ...
- 参数化取值策略Sequential
1.Sequential+Each iteration(顺序方式+每次迭代更新取值),设置Run—Logic中action循环迭代11次,并运行以上脚本,结果如下: 2.Sequential+ ...
- SpringMVC-HandlerMapping和HandlerAdapter
网上介绍HandlerMapping和HandlerAdapter的文章很多,今天我用自己的理解和语言来介绍下HandlerMapping和HandlerAdapter 一. HandlerMappi ...
- rabbitMQ学习笔记(一)Windows 与Linux下rabbitMQ的安装
版权声明:本文为博主原创文章,未经博主允许不得转载. Normal 0 7.8 磅 0 2 false false false EN-US ZH-CN X-NONE /* Style Definiti ...
- Java n个线程轮流打印数字的问题
一. 实现两个线程.轮流打印出数字.例如以下: bThread --> 10 aThread --> 9 bThread --> 8 aThread --> 7 bThread ...
- HDU 2817 EASY题
#include <iostream> #include <cstdio> using namespace std; const __int64 MOD=200907; __i ...
- 建议53:用状态模式美化代码,关于python-state工具包的理解
在<编写高质量代码:改善python程序的91个建议>的建议53:用状态模式美化代码小节中,介绍了状态模式例如以下:就是当一个对象的内在状态改变时,同意改变其行为,但这个对象看起来 ...
- Nginx 做系统的前端反向proxy
Nginx是一款很优秀的基于event的webserver.吞吐量大.占用资源少,只是文档就很让人郁闷了,免费的Nginx和收费的Nginx+的文档共用一份,配置完之后才发现免费的Nginx启动某些命 ...
- 0x11 栈
这个不难吧,算是常识了..毕竟也是刷过USACO的人 对顶栈这东西前几天才遇到过,好像和在线求中位数那东西放一起了吧 单调栈倒是没什么...贴个代码算了.一开始有点蠢的每个位置算,后来发现出栈再算就行 ...
- mysqli的简单工具包
mysqli的简单工具包 <?php /** * 连接 * @param string $host * @param string $user * @param string $password ...