【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两种颜色的格子; 让你在这个格子 ...
随机推荐
- Virtual address cache memory, processor and multiprocessor
An embodiment provides a virtual address cache memory including: a TLB virtual page memory configure ...
- telnet允许root用户登录
默认情况下,linux不允许root用户以telnet方式登录linux主机,若要允许root用户登录,可采取以下3种方法之一: 1.修改login文件 redhat中对于远程登录的限制体现在/ ...
- F - Truck History
F - Truck History #include<cstdio> #include<cstring> #include<iostream> #include&l ...
- Scrapy系列教程(6)------怎样避免被禁
避免被禁止(ban) 有些网站实现了特定的机制,以一定规则来避免被爬虫爬取. 与这些规则打交道并不easy,须要技巧,有时候也须要些特别的基础. 假设有疑问请考虑联系 商业支持 . 以下是些处理这些网 ...
- 通过PowerShell卸载全部的SharePoint 2010 解决方式
通过PowerShell卸载全部的SharePoint 2010 解决方式 为了演示.我常常须要拆毁再重建SharePoint 2010 环境. 我常常须要用到的操作就 ...
- tomat遇到的一些错误
资料链接:启动tomcat一闪而过的问题
- log4j日志存储到数据库
一.前提条件 系统必须是使用LOG4J进行日志管理,否则方法无效. 系统必须包含commons-logging-xxx.jar,log4j-xxx.jar这两个JAR包,XXX为版本号. 二.操作步骤 ...
- poj--3207--Ikki's Story IV - Panda's Trick(2-sat)
Ikki's Story IV - Panda's Trick Time Limit: 1000MS Memory Limit: 131072KB 64bit IO Format: %I64d ...
- Java基础之关键字
一.Java关键字总览 基本数据类型(9):boolean.char.byte.short.int.long.float.double.null 变量引用(2):super.this 类.方法.变量修 ...
- isual Studio 2013编译ImageMagick---转
“该文引用自 CruiseYoung的:Visual Studio 2013编译ImageMagick http://blog.csdn.net/fksec/article/details/36008 ...