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

枣阳网站建设 枣阳山水数码自己建网站备案

枣阳网站建设 枣阳山水数码,自己建网站备案,网站建设开发团队介绍,微信开放平台是干什么用的总体思路是用并查集来做。vec记录了目前断掉的路#xff0c;use记录了使用中的路。将断掉的路按照修复费用从小到大排序。 对每一个城市i失守进行讨论#xff0c;先根据use将其中两端城市进行union#xff0c;然后计算一下联通块个数。再按序找两个城市不在同一个联通块中的…总体思路是用并查集来做。vec记录了目前断掉的路use记录了使用中的路。将断掉的路按照修复费用从小到大排序。 对每一个城市i失守进行讨论先根据use将其中两端城市进行union然后计算一下联通块个数。再按序找两个城市不在同一个联通块中的vec将其union当联通块个数变为1的时候提前退出。当遍历完后若联通块数依然超过1则将修复费用设为INF。 代码如下 #include cstdio #include vector #include algorithm #include utility #include set const int maxN 501; const int INF 99999999;struct arc{int u;int v;int cost;arc(int _u, int _v, int _cost): u(_u), v(_v), cost(_cost){} };int N, M, maxx, a, b, c, s; int fa[maxN]; std::vectorarc vec; std::vectorstd::pairint, int use; std::vectorint curr;bool cmp(const arc m, const arc n){return m.cost n.cost; }int findFather(int k){int x k;while(k ! fa[k]){k fa[k];}int t;while(x ! fa[x]){t fa[x];fa[x] k;x t;}return k; }void Union(int m, int n){fa[findFather(m)] findFather(n);return; }int main(){scanf(%d %d, N, M);for(int i 0; i M; i){scanf(%d %d %d %d, a, b, c, s);if(s 0){vec.push_back(arc(a, b, c));} else{use.push_back({a, b});}}sort(vec.begin(), vec.end(), cmp);maxx 0;for(int i 1; i N; i){for(int j 1; j N; j){fa[j] j;}for(int j 0; j use.size(); j){if(use[j].first ! i use[j].second ! i){Union(use[j].first, use[j].second);}}std::setint st;for(int j 1; j N; j){if(j ! i){st.insert(findFather(j));}}int sz st.size() - 1;if(sz 0){continue;}int tmp 0;int p 0;for(int j 0; j vec.size(); j){if(findFather(vec[j].u) ! findFather(vec[j].v) vec[j].u ! i vec[j].v ! i){tmp vec[j].cost;Union(vec[j].u, vec[j].v);p;}if(p sz){break;}}if(p sz){tmp INF;}if(tmp maxx){maxx tmp;curr.clear();curr.push_back(i);} else if(tmp maxx){curr.push_back(i);}}if(maxx 0){printf(0);return 0;}for(int i 0; i curr.size(); i){printf(%d%s, curr[i], i curr.size() - 1 ? \n : );}return 0; } 题目如下 It is vitally important to have all the cities connected by highways in a war. If a city is conquered by the enemy, all the highways from/toward that city will be closed. To keep the rest of the cities connected, we must repair some highways with the minimum cost. On the other hand, if losing a city will cost us too much to rebuild the connection, we must pay more attention to that city. Given the map of cities which have all the destroyed and remaining highways marked, you are supposed to point out the city to which we must pay the most attention. Input Specification: Each input file contains one test case. Each case starts with a line containing 2 numbers N (≤500), and M, which are the total number of cities, and the number of highways, respectively. Then M lines follow, each describes a highway by 4 integers: City1 City2 Cost Status where City1 and City2 are the numbers of the cities the highway connects (the cities are numbered from 1 to N), Cost is the effort taken to repair that highway if necessary, and Status is either 0, meaning that highway is destroyed, or 1, meaning that highway is in use. Note: It is guaranteed that the whole country was connected before the war. Output Specification: For each test case, just print in a line the city we must protest the most, that is, it will take us the maximum effort to rebuild the connection if that city is conquered by the enemy. In case there is more than one city to be printed, output them in increasing order of the city numbers, separated by one space, but no extra space at the end of the line. In case there is no need to repair any highway at all, simply output 0. Sample Input 1: 4 5 1 2 1 1 1 3 1 1 2 3 1 0 2 4 1 1 3 4 1 0Sample Output 1: 1 2Sample Input 2: 4 5 1 2 1 1 1 3 1 1 2 3 1 0 2 4 1 1 3 4 2 1Sample Output 2: 0
http://www.zqtcl.cn/news/509154/

相关文章:

  • 比较权威的房产网站合肥瑶海区地图全图高清版
  • 网站建设公司果动小学电教检查网站建设资料
  • 电子商务网站设计成功的要素青岛网页设计师
  • 门户网站平台建设方案网站开发后如何上线
  • 濮阳做网站的番禺区网络推广渠道
  • 杭州网站seo外包外链图片
  • 苏州网站建设有限公司枣阳建网站
  • 网站开发平台选择如何制作购物网站
  • 专业建设网站企业外包公司企业网站
  • 网站开发需求确认书国家商标注册官网查询系统
  • 国内个人网站建设wordpress 添加搜索
  • 网站建设创新简述网站开发具体流程
  • wordpress小说网站模板南宁企业网站seo
  • 网站开发与设计课程时间网站推广的搜索引擎推广
  • 网站首页幻灯片不显示网页设计制作项目
  • 遂宁网站建设哪家好深圳做响应式网站设计
  • 慈溪建设企业网站wordpress 增加分类字段
  • 毕业设计做系统网站wordpress修改评论框
  • 上海网站开发孵化设计者联盟官网
  • 旅游网站开发需求报告微信创建小程序
  • 不收费推广网站有哪些h5网站要多久
  • seo网站营销推广全...互联网创业好项目
  • vx小程序制作网站优化标题怎么做
  • 做旅游网站课程设计报告湘潭学校网站建设 x磐石网络
  • 接网站 建设没有网站可以做seo排名吗
  • 抚顺网站seo建设网站需要支付什么插件费用吗
  • 东台做淘宝网站电子商务是学什么
  • 建一个购物网站多少钱wordpress托管在哪里
  • 怎么建设免费网站北京最大的火车站
  • 做视频网站被判刑豫建设标 网站