#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
constexpr ll MOD = 1e9 + 7;
//constexpr ll MOD = 998244353;
//constexpr ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

ll zarts(vector<ll> &V, vector<ll> &W)
{
  ll NN = V.size();

  vector<pll> Vi(NN);
  for (ll i = 0; i < NN; i++)
  {
    Vi.at(i) = make_pair(V.at(i), i);
  }
  sort(Vi.begin(), Vi.end());

  vector<pll> iW(NN);
  ll cnt = 1;
  for (ll i = 0; i < NN; i++)
  {
    iW.at(i) = make_pair(Vi.at(i).second, cnt);

    if (i != NN - 1 && Vi.at(i).first != Vi.at(i + 1).first)
      cnt++;
  }
  sort(iW.begin(), iW.end());

  for (ll i = 0; i < NN; i++)
  {
    W.at(i) = iW.at(i).second;
  }

  return cnt;
}

class BinaryIndexedTree
{
public:
  ll N;
  vector<ll> bit;

  BinaryIndexedTree(ll n)
  {
    N = n;
    bit = vector<ll>(N + 1, 0); // 1 ~ N なので注意
  }

  ll _sum(ll i)
  {
    ll s = 0;
    while (i > 0)
    {
      s += bit.at(i);
      i -= i & -i;
    }
    return s;
  }

  ll sum(ll L, ll R) // [L, R) の総和
  {
    return _sum(R - 1) - _sum(L - 1);
  }

  ll get(ll i)
  {
    return sum(i, i + 1);
  }

  void add(ll i, ll x)
  {
    while (i <= N)
    {
      bit.at(i) += x;
      i += i & -i;
    }
  }
};

int main()
{
  ll N, M, Q;
  cin >> N >> M >> Q;

  vector<ll> T(Q), X(Q), Y(Q);
  for (ll i = 0; i < Q; i++)
  {
    cin >> T.at(i) >> X.at(i) >> Y.at(i);
    X.at(i)--;
  }

  vector<ll> Z(Q);
  ll K = zarts(Y, Z);
  map<ll, ll> YtoZ;
  vector<ll> ZtoY(K + 1);
  YtoZ[0] = 0;
  ZtoY.at(0) = 0;
  for (ll i = 0; i < Q; i++)
  {
    YtoZ[Y.at(i)] = Z.at(i);
    ZtoY.at(Z.at(i)) = Y.at(i);
  }

  vector<ll> A(N, 0), B(M, 0);
  BinaryIndexedTree C(K + 2), D(K + 2), E(K + 2), F(K + 2);
  C.add(1, N);
  D.add(1, M);

  ll ans = 0;
  for (ll q = 0; q < Q; q++)
  {
    ll t = T.at(q), x = X.at(q), y = Y.at(q);
    if (t == 1)
    {
      ll a = A.at(x);
      A.at(x) = y;

      ans -= a * D._sum(YtoZ[a] + 1);

      C.add(YtoZ[a] + 1, -1);
      C.add(YtoZ[y] + 1, 1);
      E.add(YtoZ[a] + 1, -a);
      E.add(YtoZ[y] + 1, y);

      ans += y * D._sum(YtoZ[y] + 1);

      //cerr << ans << endl;

      if (a < y)
        ans -= F.sum(YtoZ[a] + 2, YtoZ[y] + 2);
      else if (a > y)
        ans += F.sum(YtoZ[y] + 2, YtoZ[a] + 2);
    }
    else
    {
      ll a = B.at(x);
      B.at(x) = y;

      ans -= a * C._sum(YtoZ[a] + 0);

      D.add(YtoZ[a] + 1, -1);
      D.add(YtoZ[y] + 1, 1);
      F.add(YtoZ[a] + 1, -a);
      F.add(YtoZ[y] + 1, y);

      ans += y * C._sum(YtoZ[y] + 0);

      if (a < y)
        ans -= E.sum(YtoZ[a] + 1, YtoZ[y] + 1);
      else if (a > y)
        ans += E.sum(YtoZ[y] + 1, YtoZ[a] + 1);
    }

    cout << ans << endl;
    
    /*
    for (ll i = 0; i < K + 1; i++)
    {
      cerr << C.get(i + 1) << " ";
    }
    cerr << endl;
    for (ll i = 0; i < K + 1; i++)
    {
      cerr << D.get(i + 1) << " ";
    }
    cerr << endl;
    for (ll i = 0; i < K + 1; i++)
    {
      cerr << E.get(i + 1) << " ";
    }
    cerr << endl;
    for (ll i = 0; i < K + 1; i++)
    {
      cerr << F.get(i + 1) << " ";
    }
    cerr << endl
         << endl;
    //*/
  }
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair <int, int> pin;

const int N = 2e5 + 5;
const ll P = 998244353LL;
const int inf = 1 << 30;

int n, k, tot, cnt, head[N], f[N];

struct Edge {
    int to, nxt;
} e[N << 1];

inline void add(int from, int to) {
    e[++tot].to = to;
    e[tot].nxt = head[from];
    head[from] = tot;
}

template <typename T>
inline void read(T &X) {
    char ch = 0; T op = 1; 
    for (X = 0; ch > '9' || ch < '0'; ch = getchar())
        if (ch == '-') op = -1;
    for (; ch >= '0' && ch <= '9'; ch = getchar())
        X = (X * 10) + ch - '0';
    X *= op;
}

void dfs(int x, int fat, int mid) {
    int mx = -inf, mn = inf;
    for (int i = head[x]; i; i = e[i].nxt) {
        int y = e[i].to;
        if (y == fat) continue;
        dfs(y, x, mid);
        mx = max(mx, f[y]);
        mn = min(mn, f[y]);
    }
    if (mx == -inf) mx = 0;
    ++mn;
    // if (mn <= 0) {
    //     if (mn + mx > 0) {
    //         ++cnt;
    //         f[x] = -mid;
    //     } else f[x] = mn;    
    // } else {
    //     if (mx + 1 > mid) {
    //         ++cnt;
    //         f[x] = -mid;
    //     } else f[x] = mx + 1;
    // }
    if (mx + 1 > mid) {
        ++cnt;
        f[x] = -mid;
    } else if (mn + mx <= 0) f[x] = mn;
    else f[x] = mx + 1;
}

inline bool chk(int mid) {
    cnt = 0;
    for (int i = 1; i <= n; i++) f[i] = 0;
    dfs(1, 0, mid);
    if (f[1] > 0) ++cnt;
    // printf("%d:\n", mid);
    // for (int i = 1; i <= n; i++) printf("%d%c", f[i], " \n"[i == n]);
    return cnt <= k;
}

int main() {
// #ifndef ONLINE_JUDGE
//     freopen("sample.in", "r", stdin);
//     clock_t st_clock = clock();
// #endif

    read(n), read(k);
    for (int x, y, i = 1; i < n; i++) {
        read(x), read(y);
        add(x, y), add(y, x);
    }
    int l = 1, r = n, mid, res = n;
    for (; l <= r; ) {
        mid = (l + r) / 2;
        if (chk(mid)) res = mid, r = mid - 1;
        else l = mid + 1;
    }
    printf("%d\n", res);

// #ifndef ONLINE_JUDGE
//     clock_t ed_clock = clock();
//     printf("time = %f ms\n", (double)(ed_clock - st_clock) / CLOCKS_PER_SEC * 1000);
// #endif
    return 0;
}