题意:给出一个$n$个点,$n-1$条边的无向连通图,给出两个点$x,y$,经过$x$后的路径上就不能经过$y$,问可以走的路径$(u,v)$有多少条,($(u,v)$和$(v,u)$考虑为两条不同的路径). 题目分析:显然这是棵树..所以从$x$到$y$只有一条简单路径.而且以$x$到$y$的路径上的点为根的话,我们发现不能走的那些点都在$x$,$y$的子树里面.这样的话,统计出$x$子树里的点有$a$个,$y$子树里的点有$b$个,那么整棵树中可以走的路径一共就有$n*(n-1)-a*b$条…
C. Kuro and Walking Route time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Kuro is living in a country called Uberland, consisting of $$$n$$$ towns, numbered from $$$1$$$ to $$$n$$$, and $$…
C. Kuro and Walking Route time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Kuro is living in a country called Uberland, consisting of nn towns, numbered from 11 to nn, and n−1n−1 bidirectio…
Kuro is living in a country called Uberland, consisting of nn towns, numbered from 11to nn, and n−1n−1 bidirectional roads connecting these towns. It is possible to reach each town from any other. Each road connects two towns aa and bb. Kuro loves wa…
题目链接:http://codeforces.com/contest/979/problem/C Kuro is living in a country called Uberland, consisting of nn towns, numbered from 11 to nn, and n−1n−1 bidirectional roads connecting these towns. It is possible to reach each town from any other. Eac…
题意: 给出一棵树,其中有两个点,x和y,限制走了x之后的路径上不能有y,问可以走的路径(u,v)有多少条,(u,v)和(v,u)考虑为两条不同的路径. 思路: 简单树形dp,dfs统计在x到y路径(不包括x和y)之外的所有点,在x这边的有a个,y这边的有b个,那么答案就是n*(n-1) - a * b. 代码: #include <stdio.h> #include <string.h> #include <algorithm> #include <vector…
Starship Troopers Problem Description You, the leader of Starship Troopers, are sent to destroy a base of the bugs. The base is built underground. It is actually a huge cavern, which consists of many rooms connected with tunnels. Each room is occupie…
Time Limit: 1000MS Memory Limit: 30000K Description The city consists of intersections and streets that connect them. Heavy snow covered the city so the mayor Milan gave to the winter-service a list of streets that have to be cleaned of snow. These s…
题目链接:http://codeforces.com/contest/979/problem/C 大致题意 给出n个点,有n-1个边将他们链接.给出x,y,当某一路径中出现x....y时,此路不通.路径(u,v)和(v,u)是不同的. 思路:一开始大神是给每个点都用BFS找出能到的点的路径,同时记录搜索的状态,但出了点小问题,估计修正了也回超时,现在给出大神思路,因为不能自己到自己所以点对数肯定是n*(n-1)这是全部的可能,那我们只要找出不可能的情况相减,那就是答案的对不对?这是肯定的,现在我…
题目连接:http://codeforces.com/contest/979/problem/C 解题心得: 题意就是给你n个点,在点集中间有n-1条边(无重边),在行走的时候不能从x点走到y点,问你任意两点一共有多少种走法,u到v和v到u为不同的走法. 首先要明白的是n个点n-1条边就是一棵树.而在树中任意两点有且仅有一条路径.这样就简单了,先从x点dfs到y点,将唯一的一条路径标记上就将树x点和y点形成的子树分开了.然后不走标记的点就可以再次dfs的得到x点子树上的点数sumx,以及y点子树…