题意:一棵树,每个节点都有一个正的权值,将树剪断一条边,分成两棵树并使得两棵树的权值和之差的绝对值最小。求最小之差。
解法:记忆化dfs一遍,即枚举剪断每条边的情况,复杂度是O(n).
代码:
/****************************************************
* author:xiefubao
*******************************************************/
#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <string.h>
using namespace std;
#define eps 1e-8
typedef long long LL;
struct edge
{
int v;
int next;
} edges[200100];
int count1=0;
int head[100100];
void addedge(int u,int v)
{
edges[count1].v&