当前位置: 首页 > 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://wiki.neutronadmin.com/news/296024/

相关文章:

  • 房地产网站广告销售怎么做银川网站建设就找湖海
  • ps网站建设目标海外引流推广平台
  • 网站广告联盟怎么做的用自己的服务器建网站
  • 织梦新手网站建设没有相应营业执照怎么做网站
  • 阿里巴巴网站推广方式网站建设的公司做销售
  • 嵌入式软件开发和c++软件开发上海网站建设优化价格
  • 社保局网站建设意义代理公司注册后果严重
  • 专业做网站公司24小时接单郑州建站的
  • 昌平网站建设东莞网站建设公司招聘信息
  • 郑州网站建设包括哪些看设计案例的有哪些网站
  • 在新西兰做兼职的网站成品视频直播软件推荐哪个好一点
  • 做网站怎么在图片上加文字亿度网络 网站建设
  • 哪类型网站容易做南通网站建设祥云
  • 杭州seo网站推广排名ui设计app界面设计流程
  • 安徽营销型网站建设微云怎么做网站
  • 网站后台更新了 前台不现实做婚纱网站的意义
  • 世界杯竞猜网站开发德州王霞网站建设
  • 抄袭别人网站wordpress 数据库查询插件
  • 个人网站如何建设图片分页wordpress主题
  • 网站建设站点标题在什么位置在安阳想建个网站怎么做
  • 网站的记住密码功能怎么做做网站卖掉
  • 观山湖网站建设推广在wordpress上添加播放视频播放器
  • seo批量建站方法dede和wordpress哪个安全
  • 信息最全的网站h5 高端网站建设
  • 芜湖做网站的邓健网站seo方案
  • 外贸网站谷歌seo揭阳百度关键词优化
  • 做商城网站服务器遵义做百度网站一年多少钱
  • 学到什么程度可以做网站如何免费推广自己的产品
  • 2022年ppt模板下载重庆网站seo案例
  • 外贸网站建设公司平台互联网行业现状分析