二分答案,判定连通性

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int a = (b); a <= (c); ++ a)
#define nR(a,b,c) for(register int a = (b); a >= (c); -- a)
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Abs(a) ((a) < 0 ? -(a) : (a))
#define Swap(a,b) a^=b^=a^=b
#define ll long long #define ON_DEBUG #ifdef ON_DEBUG #define D_e_Line printf("\n\n----------\n\n")
#define D_e(x) cout << #x << " = " << x << endl
#define Pause() system("pause")
#define FileOpen() freopen("in.txt","r",stdin); #else #define D_e_Line ;
#define D_e(x) ;
#define Pause() ;
#define FileOpen() ; #endif struct ios{
template<typename ATP>ios& operator >> (ATP &x){
x = 0; int f = 1; char c;
for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-') f = -1;
while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
x*= f;
return *this;
}
}io;
using namespace std; const int N = 20007;
int n, k, m; struct Node{
int x, y, w1, w2;
}a[N];
inline bool cmp_w1(const Node &a, const Node &b){
return a.w1 < b.w1;
}
inline bool cmp_w2(const Node &a, const Node &b){
return a.w2 < b.w2;
}
int fa[N];
inline int Find(int x){
return x == fa[x] ? x : fa[x] = Find(fa[x]);
}
inline bool Check(int tim){
int totTeen = 0, totLeason = 0;
R(i,1,n) fa[i] = i;
R(i,1,m){
int p = Find(a[i].x), q = Find(a[i].y);
if(p != q && tim >= a[i].w2){
if(a[i].w1 <= tim) ++totTeen;
fa[p] = q;
++totLeason;
}
}
return ((totLeason >= n - 1) && (totTeen >= k));
}
int main(){
io >> n >> k >> m;
R(i,1,m){
io >> a[i].x >> a[i].y >> a[i].w1 >> a[i].w2;
}
sort(a + 1, a + m + 1, cmp_w1);
int l = 1, r = 1e6;
while(l <= r){
int mid = (l + r) >> 1;
if(Check(mid))
r = mid - 1;
else
l = mid + 1;
}
printf("%d", l);
return 0;
}

最新文章

  1. 自己用js实现全屏滚动
  2. jquery操作select(取值,设置选中)
  3. 上传Text文档并转换为PDF(解决乱码)
  4. [JavaEE]理解ThreadLocal
  5. 工作的思考十五:升职前需要做的准备(TeamLeader)
  6. bzoj 1565 最大权闭合子图
  7. CSS Padding(填充)
  8. 自己动手做 UEStudio/UltraEdit 的语法高亮文件 (*.uew)
  9. Python 改变当前工作目录
  10. Qt 文件监视器 QFileSystemWatcher
  11. Android开发之漫漫长途 XIV——ListView
  12. Android简易实战教程--第四十八话《Android - Timer、TimerTask和Handler实现倒计时》
  13. Crontab和sudo中无法使用TensorFlow ImportError libcublas.so.9.0
  14. Error: [ng:areq] Argument ‘AppCtrl’ is not a function, got undefined
  15. Mysql中的锁机制
  16. python 经典博客链接
  17. Python常用模块--datetime
  18. Manjaro kde 18.0安装与基本配置
  19. NIO基础之同步、异步、阻塞、非阻塞
  20. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C. Ray Tracing 数学

热门文章

  1. Nanodet模型部署(ncnn,openvino)/YOLOX部署(TensorRT)
  2. vscode的一些优化设置
  3. Java 多线程共享模型之管程(上)
  4. 你难道不知道Vue-cookie?
  5. mybatis查询mysql 数据库中 BLOB字段,结果出现乱码
  6. 在.NET 6.0上使用Kestrel配置和自定义HTTPS
  7. 如果一个promise永不resolve,会内存泄漏吗
  8. Linux查看内网服务器的出口IP
  9. Mysql数据库的默认引擎
  10. 【小程序自动化Minium】三、元素定位- WXSS 选择器的使用