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

34480번 - Delivery Service 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
12 초 2048 MB86675.000%

문제

The Intercity Caspian Package Company (ICPC) is starting a delivery service which will deliver packages between various cities near the Caspian Sea. The company plans to hire couriers to carry packages between these cities.

Each courier has a home city and a destination city, and all couriers have exactly the same travel schedule: They leave their home city at 9:00, arrive at their destination city at 12:00, leave their destination city at 14:00 and return to their home city at 17:00. While couriers are in their home or destination cities, they can receive packages from and/or deliver packages to customers. They can also hand off to or receive packages from other couriers who are in that city at the same time. Since ICPC is a personal service, packages are never left in warehouses or other facilities to be picked up later – unless the package has reached its destination, couriers have to either keep the package with themselves (during the day or during the night), or hand it off to another courier.

The company will direct the couriers to hand off packages in such a way that any package can always be delivered to its destination. Or so it is hoped! We’ll say that two cities $u$ and $v$ are connected if it is possible to deliver a package from city $u$ to city $v$ as well as from $v$ to $u$. To estimate the efficiency of their hiring process, the company would like to find, after each courier is hired, the number of pairs of cities $(u, v)$ that are connected (1ドル ≤ u < v ≤ n$).

입력

The first line of input contains two integers $n$ and $m,ドル where $n$ (2ドル ≤ n ≤ 2 \cdot 10^5$) is the number of cities, and $m$ (1ドル ≤ m ≤ 4 \cdot 10^5$) is the number of couriers that will be hired. Couriers are numbered 1ドル$ to $m,ドル in the order they are hired. This is followed by $m$ lines, the $i$th of which contains two distinct integers $a_i$ and b$_i$ (1ドル ≤ a_i , b_i ≤ n$), denoting the home and destination cities, respectively, for courier $i$.

출력

Output $m$ integers, denoting the number of pairs of connected cities after hiring the first 1,ドル 2, \dots , m$ couriers.

제한

예제 입력 1

4 4
1 2
2 3
4 3
4 2

예제 출력 1

1
2
4
6
  1. After the first courier is hired, cities 1ドル$ and 2ドル$ are connected.
  2. After the second courier is hired, cities 2ドル$ and 3ドル$ are connected. Note, however, that cities 1ドル$ and 3ドル$ are still not connected. Even though there’s a courier moving between cities 1ドル$ and 2ドル,ドル and a courier moving between cities 2ドル$ and 3ドル,ドル they never meet each other.
  3. After the third courier is hired, cities 3ドル$ and 4ドル$ are connected and cities 2ドル$ and 4ドル$ are connected. For example, one way to deliver a package from city 2ドル$ to city 4ドル$ is:
    • hand it to courier 2ドル$ in city 2ドル$ at 19:00;
    • the next day, courier 2ドル$ arrives in city 3ドル$ at 12:00, and hands the package to courier 3ドル$ who is also in city 3ドル$;
    • at 18:00, courier 3ドル$ delivers the package to city 4ドル$.
  4. After the fourth courier is hired, all six pairs of cities are connected.

노트

출처

ICPC > World Finals > ICPC World Finals 2025 E번

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

출처

대학교 대회

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

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