# POJ - 2763 Housewife Wind（树链剖分）

#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>

using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define lson rt<<1
#define rson rt<<1|1
const int maxn = 1e5+10;
const int N = 1e5+10;
int a[maxn];
int n,q,s;
int e[maxn][3];
struct Edge{
int to,next;
}edge[maxn<<1];
int siz[maxn],fa[maxn],son[maxn],dep[maxn];
int p[maxn],fp[maxn],top[maxn],pos;
//线段树
int sum[maxn<<2];

void Init()
{
tot = pos = 0;
mem(son,-1);
}

void AddEdge( int u, int v)
{
edge[tot].to = v;
}

void dfs1( int u, int pre, int d)
{
siz[u] = 1;
fa[u] = pre;
dep[u] = d;
for( int i = head[u]; ~i; i = edge[i].next)
{
int v = edge[i].to;
if( v != fa[u])
{
dfs1(v,u,d+1);
siz[u] += siz[v];
if( son[u] == -1 || siz[v] > siz[son[u]])
son[u] = v;
}
}
}

void dfs2( int u, int tp)
{
top[u] = tp;
p[u] = ++pos;
fp[p[u]] = u;
if( son[u] == -1)
return;
dfs2(son[u],tp);
for( int i = head[u]; ~i; i = edge[i].next)
{
int v = edge[i].to;
if( v != fa[u] && v != son[u])
dfs2(v,v);
}
}

void PushUp( int rt)
{
sum[rt] = sum[lson]+sum[rson];
}

void Build( int l, int r, int rt)
{
if( l == r)
{
sum[rt] = a[l];
return;
}
int mid = (l+r)>>1;
Build(l,mid,lson);
Build(mid+1,r,rson);
PushUp(rt);
}

void Update( int l, int r, int rt, int k, int val)
{
if( l == r)
{
sum[rt] = val;
return;
}
int mid = (l+r)>>1;
if( k <= mid)
Update(l,mid,lson,k,val);
else
Update(mid+1,r,rson,k,val);
PushUp(rt);
}

int Query( int l, int r, int rt, int L, int R)
{
if( L <= l && R >= r)
return sum[rt];
int mid = (l+r)>>1;
if( R <= mid)
return Query(l,mid,lson,L,R);
else if( L > mid)
return Query(mid+1,r,rson,L,R);
else
return Query(l,mid,lson,L,mid)+Query(mid+1,r,rson,mid+1,R);
}

int Find( int u, int v)
{
int ans = 0;
int t1 = top[u];
int t2 = top[v];
while( t1 != t2)
{
if( dep[t1] < dep[t2])
{
swap(u,v);
swap(t1,t2);
}
ans += Query(1,pos,1,p[t1],p[u]);
u = fa[t1];
t1 = top[u];
}
if( u == v)
return ans;
if( dep[u] > dep[v])
swap(u,v);
ans += Query(1,pos,1,p[son[u]],p[v]);
return ans;
}

int main()
{
while( ~scanf("%d%d%d",&n,&q,&s))
{
Init();
for( int i = 1; i < n; i++)
{
scanf("%d%d%d",&e[i][0],&e[i][1],&e[i][2]);
}

dfs1(1,0,0);
dfs2(1,1);

for( int i = 1; i < n; i++)
{
if( dep[e[i][0]] > dep[e[i][1]])
swap(e[i][0],e[i][1]);
a[p[e[i][1]]] = e[i][2];
}
Build(1,pos,1);

while( q--)
{
int op,u,i,w;
scanf("%d",&op);
if( op == 0)
{
scanf("%d",&u);
printf("%d\n",Find(s,u));
s = u;
}
else if( op == 1)
{
scanf("%d%d",&i,&w);
//                Update(1,pos,1,p[e[i][1]],w);
Update(1,pos,1,p[e[i][1]],w);
}
}
}

return 0;
}