一、题目
二、解法
有一个明显的思路,就是对于每一个 a a a的取值,我们找到最小的 b b b,用它们去更新答案。
具体来说,先把边按 a a a从小到大排序,然后对于当前的 a a a,就把它当做最大的 a a a,现在我们要让最大的 b b b最小,这不就是最小生成树吗,只是我们要动态维护,剩下的就变成了这道题,贴上代码:
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
const int M = 150005;
int read()
{
int x=0,flag=1;
char c;
while((c=getchar())<'0' || c>'9') if(c=='-') flag=-1;
while(c>='0' && c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
return x*flag;
}
int n,m,t,ans,par[M],ch[M][2],Max[M],val[M],pos[M],fl[M],st[M];
struct node
{
int u,v,x,y;
bool operator < (const node &R) const
{
return x<R.x;
}
}<