This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n+1)
#define RREP(i, n) for (int i=(n)-1; i>=0; i--)
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)((x).size())
const ll maxn = 1e5+5;
int n;
string str;
vector<pii> op(maxn);
vector<int> par(maxn);
void inp(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin>>n;
    cin>>str;
    REP(i, n-1){
        cin>>op[i].f>>op[i].s;
        op[i].f--;
        op[i].s--;
    }
}
vector<string> vc(maxn);
int fin(int a){
    if (a==par[a]) return a;
    return par[a] = fin(par[a]);
}
void merg(int a, int b){
    a=fin(a); b=fin(b);
    assert(a!=b);
    par[b]=a;
    vc[a]+=vc[b];
}
int cunt(string &a){
    set<string> st;
    REP(i, SZ(a)){
        string tmp, tmp2;
        FOR(j, i, SZ(a)){
            tmp2=tmp=a.substr(i, j-i+1);
            reverse(ALL(tmp2));
            if (tmp == tmp2) st.insert(tmp);
        }
    }
    return SZ(st);
}
void solve(){
    REP(i, n){
        vc[i]=str[i];
    }
    REP1(i, n){
        par[i]=i;
    }
    REP(i, n-1){
        merg(op[i].f, op[i].s);
        string t = vc[fin(op[i].f)];
        cout<<cunt(t)<<endl;
    }
}
signed main(){
    inp();
    solve();
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |