bzoj4198 noi2015 Homer Epic

Source: Internet
Author: User

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&GT;T2) return sta1[h1++];
	if (H1&GT;T1) return sta2[h2++];
		if (sta1[h1].num==sta2[h2].num) {if (STA1[H1].DEP&LT;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< 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.