按题意枚举每个点,建立缺少该点情况下的最小生成树,取权值最大的~

#include<bits/stdc++.h>
using namespace std;
const int maxn=;
const int inf=1e9;
int g[maxn][maxn];
int visit[maxn];
int d[maxn];
int N,M,x,y;
int flag;
int prim (int s) {
fill (d,d+maxn,inf);
d[s]=;
int ans=;
for (int i=;i<=N-;i++) {
int u=-,min=inf;
for (int j=;j<=N;j++)
if (!visit[j]&&d[j]<min) {
u=j;
min=d[j];
}
if (u==-) return inf;
visit[u]=;
ans+=d[u];
for (int v=;v<=N;v++)
if (!visit[v]&&g[u][v]!=inf&&g[u][v]<d[v]) d[v]=g[u][v];
}
return ans;
}
int main () {
scanf ("%d %d",&N,&M);
for (int i=;i<=N;i++)
for (int j=;j<=N;j++)
g[i][j]=inf;
for (int i=;i<M;i++) {
scanf ("%d %d",&x,&y);
scanf ("%d %d",&g[x][y],&flag);
if (flag==) g[x][y]=;
g[y][x]=g[x][y];
}
vector<int> vi;
int Max=-;
for (int i=;i<=N;i++) {
fill (visit,visit+maxn,);
visit[i]=;
int j=i<N?i+:;
int mst=prim(j);
if (mst>Max) {
vi.clear();
vi.push_back(i);
Max=mst;
}
else if (mst==Max) {
vi.push_back(i);
}
}
if (Max==) {
printf ("");
return ;
}
for (int i=;i<vi.size();i++) {
if (i!=) printf (" ");
printf ("%d",vi[i]);
}
return ;
}

PAT T1001 Battle Over Cities-Hard Version的更多相关文章

  1. PAT-Top1001. Battle Over Cities - Hard Version (35)

    在敌人占领之前由城市和公路构成的图是连通图.在敌人占领某个城市之后所有通往这个城市的公路就会被破坏,接下来可能需要修复一些其他被毁坏的公路使得剩下的城市能够互通.修复的代价越大,意味着这个城市越重要. ...

  2. PAT 1013 Battle Over Cities

    1013 Battle Over Cities (25 分)   It is vitally important to have all the cities connected by highway ...

  3. PAT 1013 Battle Over Cities(并查集)

    1013. Battle Over Cities (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It ...

  4. pat 1013 Battle Over Cities(25 分) (并查集)

    1013 Battle Over Cities(25 分) It is vitally important to have all the cities connected by highways i ...

  5. PAT 1013 Battle Over Cities (dfs求连通分量)

    It is vitally important to have all the cities connected by highways in a war. If a city is occupied ...

  6. PAT A1013 Battle Over Cities (25 分)——图遍历,联通块个数

    It is vitally important to have all the cities connected by highways in a war. If a city is occupied ...

  7. PAT 1013 Battle Over Cities DFS深搜

    It is vitally important to have all the cities connected by highways in a war. If a city is occupied ...

  8. pat1001. Battle Over Cities - Hard Version 解题报告

    /**题目:删去一个点,然后求出需要增加最小代价的边集合生成连通图思路:prim+最小堆1.之前图中未破坏的边必用,从而把两两之间可互达的点集合 合并成一个点2.求出不同点集合的最短距离,用prim+ ...

  9. 「日常训练」Battle Over Cities - Hard Version(PAT-TOP-1001)

    题意与分析 题意真的很简单,实在不想讲了,简单说下做法吧. 枚举删除每个点,然后求最小生成树,如果这个路已经存在那么边权就是0,否则按照原来的处理,之后求花费,然后判整个图是否联通(并查集有几个roo ...

随机推荐

  1. 思科ISE配置专题–ISE部署方式

    ISE部署方式有三种: 1.Standalong Deployment 所谓Standalong部署就是只有一台ISE,所有的组件都安装在这一台上面.一台ISE装好的时候默认是“Standalong” ...

  2. 数据库程序接口——JDBC——功能第五篇——批量处理

    综述 批量处理一般指批量插入,批量更新,删除通过可以指定where条件实现.批量插入的实现方式有三种类型.statement,preparedStatement,callableStatement. ...

  3. nginx.conf nginx反向代理配置文件

    nginx反向代理配置文件 nginx.conf proxy_default.conf proxy.conf vhost/*.conf upstream/*.conf cache/*.conf ngi ...

  4. mysql开启远程访问及相关权限控制

    开启mysql远程访问: 授予用户user 密码 passwd 所有权限 所有主机IP可访问 授权语句:Grant <权限> on 表名[(列名)] to 用户 With grant op ...

  5. ci/cd部署时遇到的一个问题

    今天在部署项目的时候报了一个错Error  response  from  daemon:  endpoint  with  name  xxx already  exists  in  networ ...

  6. 理解Javascript的原型和原型链

    前言 本文2088字,阅读大约需要13分钟. 总括: 结合实例阐述了原型和原型链的概念并总结了几种创建对象的方法,扩展原型链的方法. 参考文章:The Secret Life of Objects,继 ...

  7. Python - 装饰器实现缓存

    from functools import wraps def cache(func): cache = {} @wraps(func) def wrap(*args): if args not in ...

  8. [踩坑记录] windows10 应用商店打不开 代码: 0x80131500

    在某博客看到的方法,供参考,可以尝试一下,我的也是这么解决的1.打开“运行”输入 inetcpl.cpl (“WINDOWS”+“R”键,输入 inetcpl.cpl亦可)2.点开高级往下拉,勾上&q ...

  9. ES6-三点运算符

    首先理解一下函数总的arguments变量,这个变量是函数内部自动生成的,他用来保存传入函数的实参,是一个伪数组. 例: function fun(a,b){ console.log(argument ...

  10. 洛谷 P1063 能量项链(区间DP)

    嗯... 题目链接:https://www.luogu.com.cn/problem/P1063 这道题首先要读懂题目,然后往上套区间dp,要转换成链式. AC代码: #include<cstd ...