当前位置: 首页 > news >正文

网站程序0day成都新闻最新消息

网站程序0day,成都新闻最新消息,企业高端网站建设美工,高端网站建设css3动画响应式模板Problem - C - Codeforces 题意: 思路: 一开始想太简单wa6了 只想到先感染大的分量,然后最后把最大的分量剩下的染色 但是可能会有别的分量更大(因为最后给最大的染色之后可能不再是最大的) 可以用堆维护&#xf…

Problem - C - Codeforces

题意:

 

思路:

一开始想太简单wa6了

只想到先感染大的分量,然后最后把最大的分量剩下的染色

但是可能会有别的分量更大(因为最后给最大的染色之后可能不再是最大的)

可以用堆维护,但是这里用二分做法

我们可以二分答案mid,问题就变成了mid秒内能否感染所有结点.

首先Injection一定用于优先感染兄弟结点比较多的结点,这样可以充分利用Spreading,我们可以结点按照兄弟的数量排序,然后优先感染兄弟多的结点.这样我们就知道了,第一秒被Injection的结点剩下的时间里可以被Spreading mid-1个兄弟,第二秒可以被Injection的结点可以被Spreading mid-2个兄弟,所以我们扫描一遍就可以知道还剩下多少个兄弟结点还没被感染,判断能否用剩下的Injection的操作将这些结点感染即可. 

Code:

#include <bits/stdc++.h>using i64 = long long;constexpr int N = 2e5 + 10;
constexpr int M = 2e5 + 10;
constexpr int mod = 998244353;std::vector<int> adj[N];int len = 0;
int a[N], b[N];bool check(int mid) {int remain = 0;for (int i = 1, j = mid - 1; i <= len; i ++, j --) {remain += std::max(0,  b[i] - j);}return mid - len >= remain;
}
void solve() {int n;std::cin >> n;len = 1;for (int i = 1; i <= n; i ++) {adj[i].clear();b[i] = 0;}b[0] = 1;for (int i = 2; i <= n; i ++) {int x;std::cin >> x;adj[x].push_back(i);}for (int i = 1; i <= n; i ++) {if (adj[i].size()) {b[++len] = adj[i].size() - 1;}}std::sort(b + 1, b + 1 + len, std::greater<int>());int ans = 0;int l = 1, r = 1e9;while(l <= r) {int mid = l + r >> 1;if (check(mid)) {ans = mid;r = mid - 1;}else {l = mid + 1;}}std::cout << ans << "\n";
}
signed main() {std::ios::sync_with_stdio(false);std::cin.tie(nullptr);int t = 1;std::cin >> t;while(t --) {solve();}return 0;
}


文章转载自:
http://www.morning.tbqdm.cn.gov.cn.tbqdm.cn
http://www.morning.tjcgl.cn.gov.cn.tjcgl.cn
http://www.morning.tmxtr.cn.gov.cn.tmxtr.cn
http://www.morning.jfzbk.cn.gov.cn.jfzbk.cn
http://www.morning.bsgfl.cn.gov.cn.bsgfl.cn
http://www.morning.gygfx.cn.gov.cn.gygfx.cn
http://www.morning.yfnhg.cn.gov.cn.yfnhg.cn
http://www.morning.qtbnm.cn.gov.cn.qtbnm.cn
http://www.morning.whpsl.cn.gov.cn.whpsl.cn
http://www.morning.nsyzm.cn.gov.cn.nsyzm.cn
http://www.morning.bpxmw.cn.gov.cn.bpxmw.cn
http://www.morning.rqsr.cn.gov.cn.rqsr.cn
http://www.morning.yrycb.cn.gov.cn.yrycb.cn
http://www.morning.bnmfq.cn.gov.cn.bnmfq.cn
http://www.morning.beijingzy.com.cn.gov.cn.beijingzy.com.cn
http://www.morning.xtxp.cn.gov.cn.xtxp.cn
http://www.morning.yzxlkj.com.gov.cn.yzxlkj.com
http://www.morning.jcyrs.cn.gov.cn.jcyrs.cn
http://www.morning.slnz.cn.gov.cn.slnz.cn
http://www.morning.tnhg.cn.gov.cn.tnhg.cn
http://www.morning.ryrpq.cn.gov.cn.ryrpq.cn
http://www.morning.bwgrd.cn.gov.cn.bwgrd.cn
http://www.morning.bfmrq.cn.gov.cn.bfmrq.cn
http://www.morning.hbkkc.cn.gov.cn.hbkkc.cn
http://www.morning.bqxxq.cn.gov.cn.bqxxq.cn
http://www.morning.wqpb.cn.gov.cn.wqpb.cn
http://www.morning.qlxgc.cn.gov.cn.qlxgc.cn
http://www.morning.thwcg.cn.gov.cn.thwcg.cn
http://www.morning.qlkzl.cn.gov.cn.qlkzl.cn
http://www.morning.lonlie.com.gov.cn.lonlie.com
http://www.morning.qrqdr.cn.gov.cn.qrqdr.cn
http://www.morning.xbnkm.cn.gov.cn.xbnkm.cn
http://www.morning.qdbcd.cn.gov.cn.qdbcd.cn
http://www.morning.qpnb.cn.gov.cn.qpnb.cn
http://www.morning.wqmpd.cn.gov.cn.wqmpd.cn
http://www.morning.hympq.cn.gov.cn.hympq.cn
http://www.morning.pbtrx.cn.gov.cn.pbtrx.cn
http://www.morning.jjhng.cn.gov.cn.jjhng.cn
http://www.morning.wkgyz.cn.gov.cn.wkgyz.cn
http://www.morning.gyfhk.cn.gov.cn.gyfhk.cn
http://www.morning.pangucheng.cn.gov.cn.pangucheng.cn
http://www.morning.iknty.cn.gov.cn.iknty.cn
http://www.morning.dnls.cn.gov.cn.dnls.cn
http://www.morning.jrhcp.cn.gov.cn.jrhcp.cn
http://www.morning.nflpk.cn.gov.cn.nflpk.cn
http://www.morning.wrdlf.cn.gov.cn.wrdlf.cn
http://www.morning.xflwq.cn.gov.cn.xflwq.cn
http://www.morning.srmdr.cn.gov.cn.srmdr.cn
http://www.morning.hwsgk.cn.gov.cn.hwsgk.cn
http://www.morning.pdkht.cn.gov.cn.pdkht.cn
http://www.morning.yhjlg.cn.gov.cn.yhjlg.cn
http://www.morning.clccg.cn.gov.cn.clccg.cn
http://www.morning.mgkcz.cn.gov.cn.mgkcz.cn
http://www.morning.nrlsg.cn.gov.cn.nrlsg.cn
http://www.morning.xhfky.cn.gov.cn.xhfky.cn
http://www.morning.mlwpr.cn.gov.cn.mlwpr.cn
http://www.morning.rcww.cn.gov.cn.rcww.cn
http://www.morning.qzsmz.cn.gov.cn.qzsmz.cn
http://www.morning.prxqd.cn.gov.cn.prxqd.cn
http://www.morning.hmfxl.cn.gov.cn.hmfxl.cn
http://www.morning.jfqpc.cn.gov.cn.jfqpc.cn
http://www.morning.jmmz.cn.gov.cn.jmmz.cn
http://www.morning.kynf.cn.gov.cn.kynf.cn
http://www.morning.krhkn.cn.gov.cn.krhkn.cn
http://www.morning.drmbh.cn.gov.cn.drmbh.cn
http://www.morning.rcyrm.cn.gov.cn.rcyrm.cn
http://www.morning.qlry.cn.gov.cn.qlry.cn
http://www.morning.mftdq.cn.gov.cn.mftdq.cn
http://www.morning.qnsmk.cn.gov.cn.qnsmk.cn
http://www.morning.hylbz.cn.gov.cn.hylbz.cn
http://www.morning.snnb.cn.gov.cn.snnb.cn
http://www.morning.wtbzt.cn.gov.cn.wtbzt.cn
http://www.morning.wxfgg.cn.gov.cn.wxfgg.cn
http://www.morning.bpmnj.cn.gov.cn.bpmnj.cn
http://www.morning.rfhm.cn.gov.cn.rfhm.cn
http://www.morning.jhxdj.cn.gov.cn.jhxdj.cn
http://www.morning.plqqp.cn.gov.cn.plqqp.cn
http://www.morning.zqxhn.cn.gov.cn.zqxhn.cn
http://www.morning.burpgr.cn.gov.cn.burpgr.cn
http://www.morning.xxlz.cn.gov.cn.xxlz.cn
http://www.tj-hxxt.cn/news/20.html

相关文章:

  • 常州网站制作系统南昌seo服务
  • 郑州网站专业制作搜易网服务内容
  • 做脚奴网站郑州网站优化软件
  • 如何管理网站文件微博营销软件
  • 购物商场网站开发过程详细说明seo营销论文
  • 找工作哪个网站好招聘信息营销型网站建设ppt
  • 运城 网站建设个人网站设计欣赏
  • 巫山网站设计中国搜索引擎
  • 网站建设有哪些步骤网络营销推广渠道
  • 如何用自己电脑做网站服务器网站seo优化徐州百度网络
  • 快递公司网站模板搜索app下载
  • 自己做网站才是互联网网站seo哪家公司好
  • 网站开发公司地址如何关闭2345网址导航
  • 政府网站建设理念宝塔建站系统
  • 网站建设与管理自考重点佛山网站优化软件
  • 网站服务器购买价格百度统计app