题面

题解

跑两遍\(Kruskal\),第一次找出\(k\)条一级公路,第二次找出\(n - k - 1\)条二级公路,直接计算\(MST\)的权值之和即可。

代码

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#define gI gi
#define itn int
#define File(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout) using namespace std; inline int gi()
{
int f = 1, x = 0; char c = getchar();
while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
while (c >= '0' && c <= '9') {x = x * 10 + c - '0'; c = getchar();}
return f * x;
} int n, m, fa[20003], k, vis[20003];
struct OIer
{
int a, b, c1, c2, id;
} d[20003];
struct STO_Tham
{
int Id, Tham;
} ans[20003]; int getf(int u)
{
if (fa[u] == u) return u;
return fa[u] = getf(fa[u]);
} int maxx = 900000000, maxy, tot; inline bool cmp(OIer x, OIer y) {return x.c1 < y.c1;} inline bool cmp1(OIer x, OIer y) {return x.c2 < y.c2;} inline bool OrzTham(STO_Tham x, STO_Tham y) {return x.Id < y.Id;} int main()
{
//File("P2323");
n = gi(), k = gi(), m = gi(); --m;
for (int i = 1; i <= m; i+=1)
{
d[i].a = gi(), d[i].b = gi(), d[i].c1 = gi(), d[i].c2 = gi(), d[i].id = i;
}
for (int i = 1; i <= n; i+=1) fa[i] = i;
sort(d + 1, d + 1 + m, cmp);
for (int i = 1; i <= m; i+=1)
{
int u = getf(d[i].a), v = getf(d[i].b);
if (u != v)
{
fa[u] = v;
ans[++tot].Id = d[i].id, ans[tot].Tham = 1;
maxy = max(maxy, d[i].c1);
if (tot == k) break;
}
}
sort(d + 1, d + 1 + m, cmp1);
for (int i = 1; i <= m; i+=1)
{
int u = getf(d[i].a), v = getf(d[i].b);
if (u != v)
{
fa[u] = v;
ans[++tot].Id = d[i].id, ans[tot].Tham = 2;
maxy = max(maxy, d[i].c2);
if (tot == n - 1) break;
}
}
sort(ans + 1, ans + 1 + tot, OrzTham);
printf("%d\n", maxy);
for (int i = 1; i < n; i+=1) printf("%d %d\n", ans[i].Id, ans[i].Tham);
return 0;
}

最新文章

  1. 浅谈cssText
  2. 由浅入深剖析.htaccess
  3. 如何判断js中对象的类型
  4. Linux下的GNU Emacs 24命令_信息竞赛使用_C++
  5. maven仓库有jar包,还是找不到类
  6. LR工具使用之场景设置
  7. new-nav-js
  8. ionic build android 报错分析
  9. Linux comands
  10. hdfs[命令] dfsadmin
  11. oracle安装报错检查操作系统版本: 必须是5.1 or 5.2。实际为 6.1未通过
  12. 大虾翻译(一):jQuery.extend()
  13. Serverlet具体解释
  14. 密码配置配置SSH免密码登陆
  15. application之OnLowMemory()和 OnTrimMemory(level)讲解
  16. 如何设置Linux(Centos)系统定期任务(corntab详细用法)
  17. Android - JSON Parser Tutorial
  18. 如何在Linux(Ubuntu)上安装Redmine
  19. UVAL 4728 Squares(旋转卡壳)
  20. ES6 变量的解构

热门文章

  1. 备战2020年金三银四,看这一篇面试文章就够了(合适各级Java人员)
  2. 洛谷P1067 多项式输出 NOIP 2009 普及组 第一题
  3. 问题 I: 排名
  4. script标签引入脚本的引入位置与效果
  5. Codeforces667D(spfa+dp)
  6. yii2 分页
  7. pip工具下载速度慢的问题
  8. Win10安装5 —— 系统安装步骤
  9. 《深入理解java虚拟机》读书笔记八——第九章
  10. Python调用百度地图API实现批量经纬度转换为实际省市地点(api调用,json解析,excel读取与写入)