CF1276B.Two Fairs
普及+/提高
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n cities in Berland and some pairs of them are connected by two-way roads. It is guaranteed that you can pass from any city to any other, moving along the roads. Cities are numerated from 1 to n.
Two fairs are currently taking place in Berland — they are held in two different cities a and b (1≤a,b≤n; a=b).
Find the number of pairs of cities x and y (x=a,x=b,y=a,y=b) such that if you go from x to y you will have to go through both fairs (the order of visits doesn't matter). Formally, you need to find the number of pairs of cities x,y such that any path from x to y goes through a and b (in any order).
Print the required number of pairs. The order of two cities in a pair does not matter, that is, the pairs (x,y) and (y,x) must be taken into account only once.
伯兰有 n 座城市,其中某些城市对之间由双向道路连接。保证任意两座城市之间均可通过道路相互到达。城市编号为 1 到 n。
目前伯兰正在举办两场集市——分别位于两座不同的城市 a 和 b(1≤a,b≤n;a=b)。
请找出满足以下条件的城市对 (x,y) 的数量:x=a,x=b,y=a,y=b,且从 x 到 y 的任意路径都必须经过这两座集市所在的城市 a 和 b(访问顺序不限)。形式化地说,你需要找出满足如下条件的城市对 (x,y) 的数量:任意一条从 x 到 y 的路径均同时经过 a 和 b(顺序不限)。
请输出满足条件的城市对的数量。注意:城市对中两个城市的顺序无关紧要,即 (x,y) 与 (y,x) 视为同一对,仅计一次。
输入格式
The first line of the input contains an integer t (1≤t≤4⋅104) — the number of test cases in the input. Next, t test cases are specified.
The first line of each test case contains four integers n, m, a and b (4≤n≤2⋅105, n−1≤m≤5⋅105, 1≤a,b≤n, a=b) — numbers of cities and roads in Berland and numbers of two cities where fairs are held, respectively.
The following m lines contain descriptions of roads between cities. Each of road description contains a pair of integers ui,vi (1≤ui,vi≤n, ui=vi) — numbers of cities connected by the road.
Each road is bi-directional and connects two different cities. It is guaranteed that from any city you can pass to any other by roads. There can be more than one road between a pair of cities.
The sum of the values of n for all sets of input data in the test does not exceed 2⋅105. The sum of the values of m for all sets of input data in the test does not exceed 5⋅105.
输入的第一行包含一个整数 t(1≤t≤4⋅104),表示输入中测试用例的数量。接下来给出 t 个测试用例。
每个测试用例的第一行包含四个整数 n、m、a 和 b(4≤n≤2⋅105,n−1≤m≤5⋅105,1≤a,b≤n,且 a=b),分别表示 Berland 国家的城市数量、道路数量,以及举办集市的两个城市的编号。
接下来的 m 行描述城市之间的道路。每行包含一对整数 ui,vi(1≤ui,vi≤n,ui=vi),表示由该道路连接的两座城市的编号。
每条道路均为双向道路,且连接两个不同的城市。保证任意两座城市之间均可通过道路相互到达。两座城市之间可能存在多条道路。
所有测试用例中 n 的总和不超过 2⋅105;所有测试用例中 m 的总和不超过 5⋅105。
输出格式
Print t integers — the answers to the given test cases in the order they are written in the input.
输出 t 个整数——即按输入中给出的顺序,对应各测试用例的答案。
输入输出样例
输入#1
3 7 7 3 5 1 2 2 3 3 4 4 5 5 6 6 7 7 5 4 5 2 3 1 2 2 3 3 4 4 1 4 2 4 3 2 1 1 2 2 3 4 1
输出#1
4 0 1
输入解题思路,AI测评打分。不知道怎么写?