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

#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. Stylus-import

    Stylus Import Disclaimer: In all places the @import is used with Stylus sheets, the @require could b ...

  2. 接入HikariCP遇到问题

    老Tomcat项目在接入HikariCP时遇到报错: Caused by: java.lang.AbstractMethodError: com.mysql.jdbc.Connection.isVal ...

  3. Python 摄像头 树莓派 USB mjpb

    import cv2 import urllib.request import numpy as np import sys host = "192.168.1.109:8080" ...

  4. 每天进步一点点------入门视频采集与处理(BT656简介)

    凡是做模拟信号采集的,很少不涉及BT.656标准的,因为常见的模拟视频信号采集芯片都支持输出BT.656的数字信号,那么,BT.656到底是何种格式呢?      本文将主要介绍 标准的 8bit B ...

  5. dk7和jdk8的一些新特性

    本文是我学习了解了j 的一些资料,有兴趣的大家可以浏览下下面的内容. 官方文档:http://www.oracle.com/technetwork/java/javase/jdk7-relnotes- ...

  6. 【转】Vue.js 2.0 快速上手精华梳理

    Vue.js 2.0 快速上手精华梳理 Sandy 发掘代码技巧:公众号:daimajiqiao 自从Vue2.0发布后,Vue就成了前端领域的热门话题,github也突破了三万的star,那么对于新 ...

  7. Windows上搭建hexo博客

    1.windows上下载git(官网太慢),建议去其他地方下载啊(右键出现 Git Bash Here 的标志就安装完成) 2.安装npm:http://nodejs.cn/download/ 3.安 ...

  8. Linux安装Redis服务

    下载:wget  http://download.redis.io/releases/redis-5.0.5.tar.gz 解压:tar -zxvf redis-5.0.5.tar.gz 进入redi ...

  9. 解决idea无法下载通过maven添加的jar包以及下载网速过慢的问题

    在idea上使用Maven来添加依赖的jar包 发现无法下载jar包 总是提示某几个包下载失败 最后发现原因有两个(版本与网速的问题 对应解决如下) 一主要是因为版本的问题 我的idea是2019年1 ...

  10. Dirjkstra

    Description 给定n个点,m条有向边 求每个点到1号点的最短距离 Input 第一行两个数为n,m,n表示顶点个数,m表示边的条数. (1 ≤ n, m ≤ 100 ) 接下来m行,每一行有 ...