【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

把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的更多相关文章

  1. 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时,此路不通.路 ...

  2. Codeforces Round #482 (Div. 2) :C - Kuro and Walking Route

    题目连接:http://codeforces.com/contest/979/problem/C 解题心得: 题意就是给你n个点,在点集中间有n-1条边(无重边),在行走的时候不能从x点走到y点,问你 ...

  3. 【Codeforces Round #482 (Div. 2) B】Treasure Hunt

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 我们考虑每个字符串中出现最多的字母出现的次数cnt[3] 对于这3个cnt的值. 如果cnt+n<=s[i].size 那么显 ...

  4. 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers

    [链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...

  5. 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes

    [题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...

  6. 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees

    [题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...

  7. 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory

    [题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...

  8. 【Codeforces Round #423 (Div. 2) C】String Reconstruction

    [Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...

  9. 【Codeforces Round #423 (Div. 2) B】Black Square

    [Link]:http://codeforces.com/contest/828/problem/B [Description] 给你一个n*m的格子; 里面包含B和W两种颜色的格子; 让你在这个格子 ...

随机推荐

  1. 获取DATA的数据

    num=DataTable("参数名",dtGlobalSheet) 'systemutil.Run "C:\Program Files (x86)\HP\QuickTe ...

  2. HDU 3507

    斜率DP入门题.推荐看看这篇http://www.cnblogs.com/ka200812/archive/2012/08/03/2621345.html 看过之后,自己思考,发现有些不妥之处就是,其 ...

  3. 在IntelliJ IDEA中创建Web项目

    在IntelliJ IDEA中创建Web项目 在IntelliJ IDEA中创建Web项目1,创建Maven WebProject选择File>New>Project 出现New Proj ...

  4. HDU 3342 -- Legal or Not【裸拓扑排序 &amp;&amp;水题 &amp;&amp; 邻接表实现】

    Legal or Not Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tot ...

  5. 第18题 Remove Element

    Given an array and a value, remove all instances of that value in place and return the new length. T ...

  6. mysql设置远程訪问数据库的多种方法

    问题:MySQL权限设置正确,但仍无法远程訪问.通过telnet发现3306port未打开. 分析:MySQL默认仅仅绑定127.0.0.1,即:仅仅有在本机才干訪问3306port. 解决:找到My ...

  7. Android 对话框(Dialog) 及 自己定义Dialog

    Activities提供了一种方便管理的创建.保存.回复的对话框机制,比如 onCreateDialog(int), onPrepareDialog(int, Dialog), showDialog( ...

  8. VC 6.0中添加库文件和头文件 【转】

    本文转载自:http://blog.sina.com.cn/s/blog_9d3971af0102wxjq.html 加头文件包含 VC6.0中: VC6.0默认include包含路径:Tools&g ...

  9. 0x26 广搜变形

    电路维修 这道题虽然乍一看就会想斜对角的两点之间边权受初始电路的影响要么为0要么为1,但是有一个思考点就是可以通过奇偶性,证明相邻的两个点是不可能在同一个电路中.练习一下双端队列. #include& ...

  10. idea设置Template

    在eclipse里面经常会用到syso和main类似这样的内容,但是idea工具里面没有,可以通过 Editor ==> Live templates  ==> 1.首先创建一个自己的Te ...