传送门

文章目录

  • 题意:
  • 思路:

题意:

给你nnn个点,mmm条边,限制xxx,每个点都有沥青aia_iai​,定义合并两个点即两点之间有边且au+av≥xa_u+a_v\ge xau​+av​≥x,合并之后的沥青为au+av−xa_u+a_v-xau​+av​−x,现在让你输出一种选选边方式,选n−1n-1n−1条边使得nnn个点联通。
n,m<=3e5,n−1≤m,1≤x,ai≤1e9n,m<=3e5,n-1\le m,1\le x,a_i \le1e9n,m<=3e5,n−1≤m,1≤x,ai​≤1e9

思路:

首先当(n−1)∗x>suma(n-1)*x>sum_a(n−1)∗x>suma​的时候,显然无解,否则一定能构造出一组解。
证明:
(1)(1)(1)当有一个点ai≥xa_i\ge xai​≥x的时候,显然可以将他与任意一个点合并,让后转换成n−1n-1n−1个点的子问题。
(2)(2)(2)当所有点ai<xa_i<xai​<x的时候,那么一定有两个点au+av≥xa_u+a_v\ge xau​+av​≥x,否则如果所有点au+av<xa_u+a_v<xau​+av​<x,那么a1+2∗(a2+...+an−1)+an<(n−1)∗xa_1+2*(a_2+...+a_{n-1})+a_n<(n-1)*xa1​+2∗(a2​+...+an−1​)+an​<(n−1)∗x,所以sum<(n−1)∗xsum<(n-1)*xsum<(n−1)∗x。
所以我们每次都选最大的aia_iai​,之后将他与跟他相连的且不在他集合中的点合并,用优先队列 + 并查集可以轻松实现。

// Problem: F. Phoenix and Earthquake
// Contest: Codeforces - Codeforces Global Round 14
// URL: https://codeforces.com/contest/1515/problem/F
// Memory Limit: 256 MB
// Time Limit: 3000 ms
//
// Powered by CP Editor (https://cpeditor.org)//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid (tr[u].l+tr[u].r>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL,int> PII;const int N=1000010,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;int n,m,x;
LL p[N],a[N];
vector<vector<PII>>v(N);int find(int x)
{return x==p[x]? x:p[x]=find(p[x]);
}int main()
{//  ios::sync_with_stdio(false);
//  cin.tie(0);LL sum=0;scanf("%d%d%d",&n,&m,&x);for(int i=1;i<=n;i++) scanf("%lld",&a[i]),sum+=a[i],p[i]=i;for(int i=1;i<=m;i++){int a,b; scanf("%d%d",&a,&b);v[a].emplace_back(b,i); v[b].emplace_back(a,i);}if(sum<1ll*(n-1)*x) { puts("NO"); return 0; }priority_queue<PII>q;for(int i=1;i<=n;i++) q.push({a[i],i});puts("YES");for(int i=1;i<=n-1;i++){PII t=q.top(); q.pop();int u=t.Y;while(u!=find(u)){t=q.top(); q.pop();u=t.Y;}while(u==find(v[u].back().X)&&v[u].size()) v[u].pop_back();printf("%d\n",v[u].back().Y);int vv=find(v[u].back().X);a[u]+=a[vv]-x;q.push({a[u],u});p[vv]=u;if(v[u].size()<v[vv].size()) {swap(v[u],v[vv]);}v[u].insert(v[u].end(),v[vv].begin(),v[vv].end());v[vv].clear();}return 0;
}
/**/

Codeforces Global Round 14 F. Phoenix and Earthquake 思维 + 并查集相关推荐

  1. Codeforces Global Round 14 E. Phoenix and Computers 思维 + dp

    传送门 文章目录 题意: 思路: 题意: 有nnn台电脑,你可以手动打开某个电脑,如果第i−1,i+1i-1,i+1i−1,i+1台电脑都打开了,那么第iii台电脑会自动打开.不能手动打开自动打开的电 ...

  2. Codeforces Global Round 14, C. Phoenix and Towers

    problem C. Phoenix and Towers time limit per test2 seconds memory limit per test256 megabytes inputs ...

  3. Codeforces Global Round 14 E Phoenix and Computers

    大意: 一排电脑,每次可以选择打开一台电脑,如果某一台电脑相邻的左边和右边都被打开了,它会自动打开.问打开n台电脑的方案数 思路: O(n^3)做法 不难发现,在操作过程中,一台台电脑其实就是被分成了 ...

  4. Codeforces Global Round 1 晕阙记

    Codeforces Global Round 1 晕阙记 我做这场比赛的时候晕得要死.做这三道题做太久了,rating涨不起来啊! A 如果愿意的话你可以看做是膜2意义下的运算,写快速幂等各种膜运算 ...

  5. Codeforces Global Round 3

    Codeforces Global Round 3 A. Another One Bites The Dust 有若干个a,有若干个b,有若干个ab.你现在要把这些串拼成一个串,使得任意两个相邻的位置 ...

  6. Codeforces Global Round 1

    Codeforces Global Round 1 题解:The Editorial of the First Codeforces Global Round A:其实mod 2计算一下就行了 B:删 ...

  7. 【Codeforces Global Round 23】B. Rebellion

    Codeforces Global Round 23中B. Rebellion Codeforces比赛记录 文章目录 题目链接: 一.B. Rebellion 题目意思: 上思路: 总结 B. Re ...

  8. Codeforces Global Round 4-D. Prime Graph(伯特兰-切比雪夫定理)

    题目:Codeforces Global Round 4-D. Prime Graph 题意:给出n(顶点的个数),要求所得图满足: 1.无平行边和自环 2.边的总数是个质数 3.每个点的度(也就是点 ...

  9. codeforces global round 23

    constest :codeforces global round 23 contest time:2022.10.16 contest grade: 2800 contest rating chan ...

最新文章

  1. 一个基于组件的动态对象系统
  2. <论文阅读>CascadePSP: Toward Class-Agnostic and Very High-Resolution Segmentation via Global and...
  3. Linux中grep命令的12个实践例子
  4. 看漫画就能学SQL,简直太cool了
  5. iOS之深入解析Runloop的底层原理
  6. 姜汝祥的-赢在执行 - 制度执行力的三要三化
  7. python launcher卸载后蓝屏_误卸载python2.4导致yum不能用后的修复
  8. Javascript验证上传图片大小[前台处理]
  9. axios的get请求 - 代码篇
  10. 微信小程序基于scroll-view实现锚点定位
  11. Python 调试冷知识
  12. 小程序canvas转base64方法 使用upng库 亲测没问题
  13. 图像处理之基础---ffmpeg 中的图像缩放
  14. 服务器ajax无响应时间,ajax 服务器响应时间
  15. 802.11e规范的服务质量保障机制
  16. java 设计连连看_软件设计之基于Java的连连看小游戏(一)——开题及游戏首页的制作...
  17. 常见的网络安全防御解决方案与实例
  18. 我的开源: UnInstaller for Windows(VBScript)
  19. java购物车设计_Java面向对象课程设计——购物车
  20. 人民币转换---java代码实现

热门文章

  1. 贝叶斯分类器_Sklearn 中的朴素贝叶斯分类器
  2. 当代年轻人,都有些不成文的规定?
  3. 那些年,冒死拍过的老师逗逼搞笑照片 !
  4. 我怀疑全国最会吹牛的人,都在这8个公众号上了
  5. navicat循环执行上下两行相减sql语句_SQL语句的优化分析
  6. linux c中动态申请二维数组,Linux C 编程详解第五篇:二维数组
  7. edge robert matlab,哪位熟悉matlab的大神路过瞄一眼哈
  8. tars框架php,TarsPHP: TARS-PHP是针对php使用tars二进制协议,以及tars平台整体运维、RPC等一系列能力的解决方案...
  9. java servlet 跳转_Servlet跳转方式sendReDirect()和forward()
  10. 算法设计与分析——递归与分治策略——循环日程赛