Under construction

Still being built. Things may change

Police Hypothesis

Time limit2sMemory limit512 MB

Summary
Given a tree with one letter per vertex, count how often pattern P appears on the path between two vertices, and handle letter updates.
Level

Hard8 of 10

Topics
Tree, String matching, Segment tree, DFS
Solved
No attempts yet

Problem

The public transport system of Nlogônia has an express network that connects the country's main tourist sites. N−1N-1 bullet trains connect NN attractions so that starting from any one tourist site, you can reach every other site using only this express network.

Graffiti is common at train stations, as it is anywhere in the world. The police noticed that every station has exactly one letter painted in a specific style. They suspect criminals are changing the graffiti to communicate, so they decided to build a system that monitors the graffiti and its changes.

Given a pattern PP, the connections between stations, and the suspicious letter at each station, write a program that handles the following operations.

  • 1 u v: Print how many times the pattern PP occurs on the path from uu to vv, reading the letters of consecutive vertices along the path.
  • 2 u x: Change the suspicious letter at station uu to xx.

Input

The first line contains two integers NN and QQ (1≤N,Q≤1051 \le N, Q \le 10^5), the number of stations and the number of operations. The second line contains the monitored pattern PP (1≤∣P∣≤1001 \le |P| \le 100). The third line contains a string SS of NN characters, the letters initially associated with each station. Each of the next N−1N-1 lines contains two integers uu and vv, meaning there is a bullet train between stations uu and vv. The next QQ lines describe the operations.

Output

For each operation of type 1, print one line containing the number of occurrences of the pattern on the analyzed path.

Examples3

  1. Example 1

    Input
    4 4
    xtc
    xtzy
    1 2
    2 3
    3 4
    1 1 3
    2 3 c
    1 1 3
    1 3 1
    
    Expected output
    0
    1
    0
    
  2. Example 2

    Input
    6 7
    lol
    dlorlx
    1 2
    1 3
    3 4
    3 5
    5 6
    1 2 6
    2 3 l
    2 6 l
    2 5 o
    1 2 6
    2 1 o
    1 6 2
    
    Expected output
    0
    1
    2
    
  3. Example 3

    Input
    5 2
    aba
    ababa
    1 2
    2 3
    3 4
    4 5
    1 1 5
    1 5 1
    
    Expected output
    2
    2