#include #include #include using namespace std; const int Nmax = 1e5+5; long long ans = 0; struct edge { int x, y; bool operator < (const edge &other) const { return x+y < other.x + other.y; } } a[Nmax]; int pos[Nmax], i, n, X, Y, b[Nmax]; vector v[Nmax]; void combine(int x, int y, int cost) { if(v[x].size() > v[y].size()) swap(x, y); int i = 0, j, nr = 0; for(j=v[x].size()-1; j>=0; --j) { nr = v[x][j]; while(i