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

19028번 - Link Cut Digraph 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 512 MB270966933.659%

문제

After reading the paper Incremental Topological Ordering and Strong Component Maintenance, you came up with the following problem.

You are given a graph with $n$ vertices. There are no edges initially. There are $m$ operations. Each operation is first to add a given directed edge to the graph, and then to output the number of pairs $(u, v)$ (1ドル \leq u < v \leq n$) such that $u$ is reachable from $v$ and $v$ is reachable from $u$.

Can you implement the algorithm described in the paper in an ICPC contest?

입력

The first line contains two integers $n$ and $m$ (1ドル \leq n \leq 10^5,ドル 1ドル \leq m \leq 2.5 \cdot 10^5$).

Each of the following $m$ lines contains two integers $u$ and $v$ (1ドル \leq u, v \leq n$) indicating a newly added directed edge. Parallel edges and self-loops are allowed.

출력

Output $m$ integers, one per line: the requested number of pairs after adding each given edge.

제한

예제 입력 1

4 6
1 2
2 3
2 1
3 4
4 3
3 2

예제 출력 1

0
0
1
1
2
6

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2018 > Day 8: Yuhao Du Contest 5, Grand Prix of Zhejiang L번

Contest > Open Cup > 2018/2019 Season > Stage 1: Grand Prix of Zheijang L번

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

출처

대학교 대회

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

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