Doubt

Revision en1, by alwaysGREEEN, 2017-10-29 16:37:00

Hello everyone ! please help in this question 682C - Alyona and the Tree Alyona and the tree. I know how to find distance between two vertices but i have no clue what to do afer that.

here's my code-:

include<bits/stdc++.h>

using namespace std;

define ll long long int

typedef vector vi; typedef map<ll,ll> mii; typedef pair<ll,ll> pii; typedef set si;

define pb push_back

define PI 3.1415926535897932384626

define boost ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)

define MOD 4294967296

define MAX 100001

define FOR(i,a,n) for (int i=(a);i<(n);++i)

define F first

define S second

define mset(x,v) memset(x, v, sizeof(x))

vector<pair<ll,ll>> v1[100002]; ll sum[100002],num[100001]; void dfs(ll x,ll par,ll wt) { sum[x]=sum[par]+wt; for(int i=0;i<v1[x].size();i++) { int node=v1[x][i].first; int wt=v1[x][i].second; if(node!=par) { dfs(node,x,wt); } } } int main() { boost; ll n,x,y; cin>>n; for(int i=1;i<=n;i++) cin>>num[i]; for(int i=1;i<=n-1;i++) { cin>>x>>y; v1[i+1].pb({x,y}); v1[x].pb({i+1,y}); } dfs(1,0,0);

}

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English alwaysGREEEN 2017-10-29 16:39:24 1177
en2 English alwaysGREEEN 2017-10-29 16:38:21 45
en1 English alwaysGREEEN 2017-10-29 16:37:00 1336 Initial revision (published)