문제
Consider an undirected graph with nodes labeled and edges (). You're given a binary string . At time for each ,
If , node is removed from the graph.If , node is removed from the graph, and edges are added between every pair of neighbors that node 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 .
입력
The first line contains and .
The second line contains the bit string of length .
The next lines each contain two integers denoting an edge of the graph.
출력
lines, the number of pairs before each timestep.
예제 입력 1
3 2
111
1 2
1 3
예제 출력 1
3
1
0
예제 입력 2
3 2
000
1 2
1 3
예제 출력 2
3
0
0
예제 입력 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
점수
Inputs 4-6: Inputs 7-8: All equal zero.Inputs 9-11: All equal one.Inputs 12-23: No additional constraints.
코드를 제출하려면 로그인이 필요합니다.
로그인