Lang:G++
Edit12345678910111213141516171819202122232425262728293031#include <bits/stdc++.h>using namespace std;typedef long long ll;vector<vector<int>> tree;vector<pair<int, int>> value;set<pair<int, int>> edges;vector<pair<ll, ll>> res;bool cmp(pair<ll, ll> p1, pair<ll, ll> p2){return p1.second > p2.second;}void dfs(int x){if(tree[x].size() == 0){res[x] = value[x];return;}ll wallet = 200000000;ll minWallet = 200000000;for(int i = 0; i < tree[x].size(); i++){dfs(tree[x][i]);}vector<pair<ll, ll>> tmp;for(int i = 0; i < tree[x].size(); i++){tmp.push_back(res[tree[x][i]]);}sort(tmp.begin(), tmp.end(), cmp);wallet = wallet - value[x].first;