#include "bits/stdc++.h"
typedef long long ll;
typedef unsigned un;
using namespace std;
typedef std::pair<ll,ll> pll;
const int MAXN = 200011,INF = 1e9+233;
pll merge(pll a,pll b){return pll(max(a.first,b.first),min(a.second,b.second));}
int n,q;
struct Segment_Tree
{
struct node
{
ll maxv,minv;
}t[MAXN<<2|1];
#define rt t[num]
void pushup(un num)
{
rt.maxv=max(t[num<<1].maxv,t[num<<1|1].maxv);
rt.minv=min(t[num<<1].minv,t[num<<1|1].minv);
}
void build(ll* arr,un l=1,un r=n,un num=1)
{
if(l==r)
{
if(arr[l]==-1)rt.maxv=0,rt.minv=INF;
else rt.maxv=rt.minv=arr[l];
return;
}
un mid=(l+r)>>1;
build(arr,l,mid,num<<1),build(arr,mid+1,r,num<<1|1);
pushup(num);
}
void modify(un pos,ll val,un l=1,un r=n,un num=1)
{
if(l==r)
{
if(val==-1)rt.maxv=0,rt.minv=INF;
else rt.maxv=rt.minv=val;
return;
}
un mid=(l+r)>>1;
if(pos<=mid)modify(pos,val,l,mid,num<<1);
else modify(pos,val,mid+1,r,num<<1|1);
pushup(num);
}
pll Query(un ql,un qr,un l=1,un r=n,un num=1)
{
if(ql<=l&&r<=qr)return pll(rt.maxv,rt.minv);
pll res(0,INF);
un mid=(l+r)>>1;
if(ql<=mid)res=merge(res,Query(ql,qr,l,mid,num<<1));
if(qr>mid)res=merge(res,Query(ql,qr,mid+1,r,num<<1|1));
return res;
}
}sgt[51];
std::vector<pll>g[MAXN],ctrb[MAXN];
int fa[MAXN],top[MAXN],loc[MAXN];
ll dis[MAXN];
int cur=0;
string s;
void push(int u,int sp,int c,ll d)
{
if(s[u]=='1')sgt[c].modify(u,d);
ctrb[u].push_back(pll(c,d));
//printf("sgt[%d] modify %d %lld\n",c,u,d);
for(auto P:g[u])
{
int v=P.first;
if(v!=sp&&v!=fa[u])push(v,sp,c,d);
}
}
void dfs(int u,int t,bool type)
{
if(type)++cur,t=u;
top[u]=t,loc[u]=cur;
//printf("loc[%d]=%d\n",u,cur);
int p=u;
while(p)
{
ctrb[u].emplace_back(pll(loc[p],dis[p]));
//printf("sgt[%d] modify %d %lld\n",loc[p],u,dis[p]);
if(s[u]=='1')sgt[loc[p]].modify(u,dis[p]);
p=fa[top[p]];
}
bool flag=0;
for(auto P:g[u])
{
int v=P.first;
ll w=P.second;
if(v==fa[u])continue;
fa[v]=u,dis[v]=dis[u]+w;
dfs(v,t,flag);
if(flag)push(u,v,cur,dis[u]);
flag=1;
}
}
int main()
{
//freopen("K.in","r",stdin);
cin.tie(0)->sync_with_stdio(0);
cin>>n>>q>>s;
s.insert(s.begin(),0);
for(int i=1;i<n;++i)
{
int u,v,w;
cin>>u>>v>>w;
g[u].emplace_back(pll(v,w));
g[v].emplace_back(pll(u,w));
}
for(int i=1;i<=n;++i)val[0][i]=-1;
for(int k=1;k<=50;++k)sgt[k].build(val[0]);
dfs(1,1,1);
while(q--)
{
int op;
cin>>op;
if(op==1)
{
int x;
cin>>x;
if(s[x]=='1')
{
for(auto P:ctrb[x])
sgt[P.first].modify(x,-1);
s[x]='0';
}
else
{
for(auto P:ctrb[x])
sgt[P.first].modify(x,P.second);
s[x]='1';
}
}
else
{
int l,r;
cin>>l>>r;
ll ans=0;
for(int k=1;k<=cur;++k)
{
pll f=sgt[k].Query(l,r);
ans+=f.first-f.second;
}
if(ans<0)cout<<"-1\n";
else cout<<(ans<<1)<<'\n';
}
}
return 0;
}