Pagini recente » Cod sursa (job #2092554) | Cod sursa (job #2118422) | Cod sursa (job #2906423) | Cod sursa (job #1690574) | Cod sursa (job #3241400)
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 1e5+2;
const int VMAX = 1e6+2;
using pii = pair<int, int>;
int n,q,k,ord[NMAX],val[NMAX];
vector<int> v[NMAX];
pii interval[NMAX];
set<int> occur[NMAX];
ifstream fin("arbore.in");
ofstream fout("arbore.out");
void dfs(int nod, int tata = -1){
ord[++k] = nod;
interval[nod] = {k, k};
for(int fiu: v[nod]){
if(fiu == tata){
continue;
}
dfs(fiu, nod);
}
interval[nod].second = k;
}
int main()
{
fin >> n >> q;
for(int i = 1; i < n; i++){
int x, y;
fin >> x >> y;
v[x].push_back(y);
v[y].push_back(x);
}
dfs(1);
while(q--){
int t, p, s;
fin >> t;
if(t == 1){
fin >> p >> s;
// update(p, s);
auto [l, r] = interval[p];
for(int j = l; j <= r; j++){
occur[val[ord[j]]].erase(ord[j]);
val[ord[j]] += s;
occur[val[ord[j]]].insert(ord[j]);
}
}else{
fin >> s;
// find(s);
if(occur[s].empty()){
fout << "-1\n";
}else{
fout << *occur[s].begin() << "\n";
}
}
}
return 0;
}