K-Fork Huffman tree, balance the whole tree can be
And then open a double queue from small to large.
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib > #include <algorithm> #define LL long long #define FO (i,a,b) for (int. i=a;i<=b;i++) #define EFO (i,x) for (int i=
Last[x];i!=0;i=e[i].next) using namespace std;
Inline LL Read () {LL D=0,f=1;char S=getchar (); while (s< ' 0 ' | |
S> ' 9 ') {if (s== '-') F=-1;s-getchar ();}
while (s>= ' 0 ' &&s<= ' 9 ') {d=d*10+s-' 0 '; S=getchar ();}
return d*f;
} #define N 100005 LL a[n],w[n];
int n,m; struct Edge {LL num,dep;}
Sta1[n],sta2[n];
LL h1=1,h2=1,t1,t2=0;
Edge Get () {if (H2>T2) return sta1[h1++];
if (H1>T1) return sta2[h2++];
if (sta1[h1].num==sta2[h2].num) {if (STA1[H1].DEP<STA2[H2].DEP) return sta1[h1++];
else return sta2[h2++];
} if (Sta1[h1].num<sta2[h2].num) return sta1[h1++];
else return sta2[h2++];
} void Add (LL x,int de) {sta2[++t2].num=x;
Sta2[t2].dep=de;
} void Check () {cout<< "new:\n"; cout<