Pagini recente » Cod sursa (job #2594411) | Cod sursa (job #2901227) | Cod sursa (job #2042286) | Cod sursa (job #2603075) | Cod sursa (job #2439182)
#include <bits/stdc++.h>
using namespace std;
ifstream f("arbore.in");
ofstream g("arbore.out");
const int NMAX = 100005;
vector <int> v[NMAX];
int n,m, lo[NMAX], hi[NMAX], father[NMAX], ans[NMAX];
vector <int> ord;
int sum[NMAX];
void dfs(int nod){
ord.push_back(nod);
lo[nod] = ord.size();
for(auto it: v[nod])
if(it != father[nod]){
father[it] = nod;
dfs(it);
}
hi[nod] = ord.size();
}
int main(){
int i,j,x,y,type;
f >> n >> m;
for(i = 1 ; i < n; i++){
f >> x >> y;
v[x].push_back(y);
v[y].push_back(x);
}
dfs(1);
ord.push_back(0);
for(i = 1 ; i <= m ; i++){
f >> type >> x;
if(type == 1){
f >> y;
for(j = lo[x] ; j <= hi[x] ; j++)
sum[j] += y;
}else{
for(j = 1 ; j <= n ; j++)
if(sum[j] == x){
g << j << "\n";
j = n + 4;
}
if(j == n + 1)
g << -1 << "\n";
}
}
return 0;
}