Under construction

Still being built. Things may change

Reachable Pairs

Time limit2sMemory limit2048 MB

Summary
Given an undirected graph and a binary string, count the reachable node pairs before each step, where a 1 removes the node and joins its neighbors and a 0 just removes it.
Level

Hard8 of 10

Topics
Graph, Union-find
Solved
No attempts yet

Problem

An undirected graph has NN nodes labeled 11 to NN and MM edges (1≤N≤2⋅1051\le N\le 2\cdot 10^5, 0≤M≤4⋅1050\le M\le 4\cdot 10^5). You are given a binary string s1s2…sNs_1s_2\dots s_N. For each timestep tt from 11 to NN, do the following.

  • If st=0s_t=0, remove node tt from the graph.
  • If st=1s_t=1, remove node tt from the graph, and add an edge between every pair of neighbors that node tt had just before its removal.

In both cases, removing a node also removes all edges incident to it.

For each timestep tt, count the pairs of nodes that can reach each other through a sequence of edges in the graph just before timestep tt.

Input

The first line contains NN and MM.

The second line contains the binary string ss of length NN.

Each of the next MM lines contains two integers, the endpoints of an edge.

Output

Print NN lines. The tt-th line contains the number of pairs of reachable nodes just before timestep tt.

Examples3

  1. Example 1

    Input
    3 2
    111
    1 2
    1 3
    
    Expected output
    3
    1
    0
    
  2. Example 2

    Input
    3 2
    000
    1 2
    1 3
    
    Expected output
    3
    0
    0
    
  3. Example 3

    Input
    7 8
    1101101
    6 2
    1 2
    2 3
    6 3
    1 3
    1 7
    4 5
    2 7
    
    Expected output
    11
    7
    4
    2
    1
    1
    0