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

33502번 - Reachable Pairs 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 2048 MB86403543.750%

문제

Consider an undirected graph with $N$ nodes labeled 1ドル\dots N$ and $M$ edges (1ドル\le N\le 2\cdot 10^5, 0\le M\le 4\cdot 10^5$). You're given a binary string $s_1s_2\dots s_N$. At time $t$ for each $t\in [1,N],ドル

  • If $s_t=0,ドル node $t$ is removed from the graph.
  • If $s_t=1,ドル node $t$ is removed from the graph, and edges are added between every pair of neighbors that node $t$ had just before removal.

Note that in both cases, when a node is removed from the graph all of its incident edges are removed as well.

Count the number of pairs of nodes that can reach each other via some sequence of edges just before each of timesteps 1ドル\ldots N$.

입력

The first line contains $N$ and $M$.

The second line contains the bit string $s$ of length $N$.

The next $M$ lines each contain two integers denoting an edge of the graph.

출력

$N$ lines, the number of pairs before each timestep.

제한

예제 입력 1

3 2
111
1 2
1 3

예제 출력 1

3
1
0

Before any removals, all pairs of nodes are reachable from each other. After node 1ドル$ is removed, an edge is added between 2ドル$ and 3ドル,ドル so they can still reach each other.

예제 입력 2

3 2
000
1 2
1 3

예제 출력 2

3
0
0

Before any removals, all pairs of nodes are reachable from each other. After node 1ドル$ is removed, 2ドル$ and 3ドル$ can no longer reach each other.

예제 입력 3

7 8
1101101
6 2
1 2
2 3
6 3
1 3
1 7
4 5
2 7

예제 출력 3

11
7
4
2
1
1
0

힌트

출처

Olympiad > USA Computing Olympiad > 2024-2025 Season > USACO 2025 January Contest > Gold 2번

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

출처

대학교 대회

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

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