[APIO2012]派遣
标签:define typename while swa putc ring cst ios dig
[APIO2012]派遣
枚举所有忍者在哪棵子树内, 答案即为本子树内最多派遣的忍者数乘上子树根在原树中祖先最强的领导力, dfs用可并堆合并两棵子树即可, 这道题用不着用并查集维护连通性
#include
#include
#include
#include
#define ll long long
using namespace std;
template
void read(T &x) {
x = 0; bool f = 0;
char c = getchar();
for (;!isdigit(c);c=getchar()) if (c=='-') f=1;
for (;isdigit(c);c=getchar()) x=x*10+(c^48);
if (f) x=-x;
}
template
void write(T x) {
if (x = 10) write(x / 10);
putchar('0' + x % 10);
}
const int N = 105000;
ll n, m;
inline ll Mx(ll x, ll y) {return x > y ? x : y;}
ll c[N], L[N];
int h[N], to[N], ne[N];
int tot;
inline void add(int x, int y) {
ne[++tot] = h[x], to[tot] = y, h[x] = tot;
}
int T[N], val[N], f[N], dis[N];
int son[N][2];
#define rs son[x][1]
#define ls son[x][0]
int merge(int x, int y) {
if (!x || !y) return x | y;
if (c[x] m) {
sum[x] -= c[T[x]]; cnt[x]--;
T[x] = merge(son[T[x]][0], son[T[x]][1]);
}
ans = Mx(ans, cnt[x] * L[x]);
}
int main() {
read(n), read(m);
for (int i = 1;i
[APIO2012]派遣
标签:define typename while swa putc ring cst ios dig
原文地址:https://www.cnblogs.com/Hs-black/p/12235634.html
评论