Lang:G++
Edit12345678910111213141516171819202122232425262728293031#include<iostream>#include<vector>using namespace std;struct Node{long value;vector<Node*> next;Node(long value) {this->value = value;}};long DFS(Node *cur, long & ans){long max_value = 0, count = 0;for(auto next:cur->next) {long value = DFS(next, ans);if(value > max_value) {ans += (value - max_value) * count;max_value = value;count++;} else {ans += max_value - value;count++;}}return max_value + cur->value;}int main(){int N;