Pagini recente » Cod sursa (job #3151976) | Borderou de evaluare (job #2477237) | Cod sursa (job #2985363) | Borderou de evaluare (job #348518) | Cod sursa (job #3259832)
#include <bits/stdc++.h>
using namespace std;
const string file="arbore";
ifstream fin(file+".in");
ofstream fout(file+".out");
#define endl "\n"
vector<int> g[100001];
int sum[100001];
void dlc(int i, int pls)
{
sum[i]+=pls;
for (auto k:g[i])dlc(k, pls);
}
int main()
{
int n, m;
fin>>n>>m;
for (int i=1; i<n; ++i){
int x, y;
fin>>x>>y;
g[x].push_back(y);
}
while (m--){
int c;
fin>>c;
if (c==1){
int x, y;
fin>>x>>y;
dlc(x, y);
} else {
fin>>c;
bool ok=true;
for (int i=1; i<=n; ++i){
if (sum[i]==c){
fout<<i<<endl;
ok=false;
break;
}
}
if (ok)fout<<"-1\n";
}
}
return 0;
}