#2235 Maintain

传送门

SOL
这道题要求动态维护MST
由于数据很小,可以每次跑Kruskal
然而sort会超时
直接插入排序即可

代码:

#include<bits/stdc++.h>
using namespace std;
#define re register
inline int rd(){int re data=0;static char ch=0;ch=getchar();while(!isdigit(ch))ch=getchar();while(isdigit(ch))data=(data<<1)+(data<<3)+(ch^48),ch=getchar();return data;
}
const int N=205,M=10005;
struct edge{int u,v,w;}e[M],tmp;
int fa[N],n,m;
inline int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
inline int kruskal(int now,int cnt=0,int sum=0,bool add=0){for(int re i=1;i<=n;++i)fa[i]=i;if(now>1){for(int re i=1;i^now;++i)if(e[i].w>tmp.w){for(int re j=now;j>i;--j)e[j]=e[j-1];e[i]=tmp,add=1;break;}if(!add)e[now]=tmp;}else e[now]=tmp;for(int re fu,fv,u,v,w,i=1;i<=now;++i){u=e[i].u,v=e[i].v,w=e[i].w,fu=find(u),fv=find(v);if(fu==fv)continue;fa[fu]=fv,sum+=w,++cnt;if(cnt==n-1)break;}if(cnt!=n-1)return -1;else return sum;
}
signed main(){n=rd(),m=rd();for(int re i=1;i<=m;++i)tmp.u=rd(),tmp.v=rd(),tmp.w=rd(),printf("%d\n",kruskal(i));exit(0);
}

[FROM WOJ]#2235 Maintain相关推荐

  1. puppet cert maintain

    puppet cert maintain posted on 2014-08-06 10:02 秦瑞It行程实录 阅读(...) 评论(...) 编辑 收藏 转载于:https://www.cnblo ...

  2. SAP QM QS41 试图维护Catalog为3的Code Group, 报错-You need to maintain catalog 3 (Usage Decisions) in Customi

    SAP QM QS41 试图维护Catalog为3的Code Group, 报错-You need to maintain catalog 3 (Usage Decisions) in Customi ...

  3. cluster maintain manager Software群集管理软件

    cluster maintain manager Software群集管理软件 1,ocfs2 2,crmsh(cluster management shell,)==crm shell [pacem ...

  4. android toolchain maintain team

    android toolchain maintain team

  5. [CareerCup] 18.9 Find and Maintain the Median Value 寻找和维护中位数

    18.9 Numbers are randomly generated and passed to a method. Write a program to find and maintain the ...

  6. Oracle 11.2.0.3 [INS-41112] Specified network interface doesnt maintain connectivity across cluster

    安装Oracle 11.2.0.3 的RAC,在Grid 安装时报错: [INS-41112]Specified network interface doesnt maintain connectiv ...

  7. Failed to maintain projects LRU cache for dir *********

    打开JetBrains系软件时(包括Android Studio),右下角有个红色小叹号总报错,强迫症看了很不爽,点开后详细内容: Failed to maintain projects LRU ca ...

  8. [转]Maintain Control State in ASP.NET 2.0

    [转自http://www.vbdotnetheaven.com] Maintain Control State in ASP.NET 2.0 By  Scott Lysle September 15 ...

  9. MAINTAIN翻译软件测试,maintain是什么意思_maintain的翻译_音标_读音_用法_例句_爱词霸在线词典...

    全部 四级 六级 高考 考研 Their life was much more comfortable than that of todayIt was helpful to maintaining ...

最新文章

  1. Photoshop CS6软件安装教程
  2. 2018/Province_Java_C/1/哪天返回
  3. 荣耀v10Android9新功能,荣耀10、荣耀V10开启安卓9.0内测 日常领跑行业
  4. python selenium 环境_配置Python Selenium环境
  5. Notification Swift 3 0
  6. SCCM 2012系列2 服务器准备下
  7. 我敢说,你的登录接口肯定不安全
  8. EMVI5.3 将数据信息改为投影坐标系
  9. AC日记——Flag Codeforces 16a
  10. copy的过去式_[copy是什么意思中文翻译成]copy是什么意思中文翻译
  11. FPGA那些事(黑金动力社区)-笔记
  12. jsd2205-csmall-passport(Day13)
  13. 以太坊性能优化:分片技术、雷电网络、Casper-下一代以太坊共识协议
  14. Notification 加入本地的声音文件
  15. remote: Repository not found. fatal: repository ‘xxxxxxx‘ not found
  16. SQL注入漏洞-GET注入
  17. matlab使用CVX求解优化问题时,如果变量搜索空间过大,导致求解的数值解相当不准确,通过变量替换,缩小搜索空间
  18. pandas转json去掉index索引
  19. VS2017安装Spy++工具
  20. 安装Windows10系统---制作U盘启动盘的方式安装

热门文章

  1. 在UCOSIII基础上对STM32F407ZGT6移植LWIP2.1.3
  2. 用git来下载github项目代码
  3. [学习笔记] Pell方程
  4. 趣头条确定发行价为7美元:今日上市
  5. Ubuntu下Java使用pdfbox将pdf转换为图片的方法及问题
  6. tp5 php post方式提交无提示,使用TP5框架时,代码提交到GitHub,无法提交thinkphp核心库...
  7. 纯英文外刊原刊在哪看?怎么看?
  8. 全球区块链第26周看点 | G20中方发言人:中国在数字货币、加密资产等领域做得较好...
  9. 4款令人骄傲的国产软件,每回买新电脑必装
  10. C++中的RTTI(转)