Roads and Libraries
来源:互联网 发布:nginx部署静态页面 编辑:程序博客网 时间:2024/05/22 10:57
Roads and Libraries
#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>using namespace std;int a[1000010];int vis[1000010];int f(int x){ if (a[x]==x){ return x; } else{ a[x]=f(a[x]); return a[x]; }}int main(){ int t; scanf("%d",&t); while(t--){ long long n,m,x1,x2; scanf("%lld%lld%lld%lld",&n,&m,&x1,&x2); for (int i=0;i<=n;i++){ a[i]=i; } long long x,y,xx=0; for (int i=1;i<=m;i++){ scanf("%lld%lld",&x,&y); a[f(y)]=f(x); } if (x1<=x2){ xx=x1*n; printf("%lld\n",xx); } else{ for (int i=1;i<=n;i++) a[i]=f(a[i]); memset(vis,0,sizeof(vis)); for (int i=1;i<=n;i++){ vis[a[i]]++; } for (int i=1;i<=n;i++){ if (vis[i]!=0){ xx=xx+(vis[i]-1)*x2+x1; } } printf("%lld\n",xx); } } return 0;}
阅读全文
0 0
- Roads and Libraries
- Roads and Libraries
- Roads and Libraries HackerRank
- Roads and Libraries(最小生成树)
- 并查集( Roads and Libraries locked)
- hackerrank Roads and Libraries(DFS/并查集)
- Static and dynamic libraries
- USACO Roads and Planes
- codeforces567E. President and Roads
- Generate Libraries and BSPs 成功
- Animation Scripts, Libraries and Plugins
- MinGW Static and Dynamic Libraries
- Linker and Libraries Guide(1)
- Fools and Foolproof Roads CodeForces
- Building and Installing ACE and Its Auxiliary Libraries and Services
- Linker and Libraries Guide Appendix D Linker and Libraries Updates and New Features
- Static, Shared Dynamic and Loadable Linux Libraries
- Asset Libraries and Blocks in iOS 4
- 探索约瑟夫问题
- Identify Smith Numbers
- UESTC 1639 云中谁寄锦书来?雁字回时,月满西楼
- 2017年第0届浙江工业大学之江学院程序设计竞赛决赛—H(图论)
- android 7.0 去掉多用户后下拉单小人人按钮点击进入联系人ME的编辑界面
- Roads and Libraries
- 关于ESP8266 GPIO中断使用的总结
- 技术团队如何培养新人
- Android View的事件分发机制与滑动冲突解决方案
- mongo数据转存(3.0版本)
- 【动态规划18】bzoj1010 [HNOI2008]玩具装箱toy(斜率优化)
- linux基础入门之绝对路径和相对路径
- 第一天
- MYSQL多表设计之表关系