Logo
(追記) (追記ここまで)

24689번 - Escaped from NEF 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB167770.000%

문제

A cactus is a connected undirected graph in which every edge lies on at most one simple cycle. Intuitively, a cactus is a generalization of a tree where some cycles are allowed. Multiedges (multiple edges between a pair of vertices) and loops (edges that connect a vertex to itself) are not allowed in a cactus.

You are given a directed graph $G$ with $n$ vertices with the following property. Consider an undirected graph $G'$ with $n$ vertices built as follows: for each directed edge $(u_i, v_i)$ in $G,ドル add an undirected edge $\{ u_i, v_i \}$ to $G'$. Then $G'$ is a cactus.

Find the number of ordered pairs of vertices $(x, y)$ such that there exists a path from vertex $x$ to vertex $y$ in $G$. Assume that a path from a vertex to itself always exists.

입력

Each test contains multiple test cases. The first line contains the number of test cases $t$ (1ドル \le t \le 10^5$). Description of the test cases follows.

The first line of each test case contains two integers $n$ and $m,ドル denoting the number of vertices and the number of edges in $G$ (2ドル \le n \le 250,000円$; $n - 1 \le m \le \left\lfloor \frac{3(n-1)}{2} \right\rfloor$).

Each of the next $m$ lines contains two integers $u_i$ and $v_i,ドル denoting an edge in $G$ directed from $u_i$ to $v_i$ (1ドル \le u_i, v_i \le n$; $u_i \ne v_i$).

The undirected graph consisting of undirected edges $\{ u_i, v_i \}$ is a cactus.

It is guaranteed that the sum of $n$ over all test cases does not exceed 250ドル,000円$.

출력

For each test case, print the number of ordered pairs $(x, y)$ such that vertex $y$ is reachable from vertex $x$ in $G$.

제한

예제 입력 1

2
3 3
1 2
1 3
2 3
5 5
1 2
2 3
3 4
4 5
4 2

예제 출력 1

6
18

힌트

출처

Camp > Petrozavodsk Programming Camp > Winter 2022 > Day 7: ICPC Camp Day 2, Gennady Korotkevich Contest 6 E번

Contest > Open Cup > 2021/2022 Season > Stage 13: Grand Prix of Gomel E번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /