PAT (Advanced Level) 1013. Battle Over Cities (25)
并查集判断连通性。
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<map>
using namespace std; const int maxn=;
struct Edge
{
int u,v;
}e[maxn*maxn];
int n,m,k;
int f[maxn]; int Find(int x)
{
if(x!=f[x]) return f[x]=Find(f[x]);
return f[x];
} int main()
{
scanf("%d%d%d",&n,&m,&k);
for(int i=;i<=m;i++)
scanf("%d%d",&e[i].u,&e[i].v); for(int i=;i<=k;i++)
{
int id; scanf("%d",&id);
int sz=n-;
for(int j=;j<=n;j++) f[j]=j;
for(int j=;j<=m;j++)
{
if(e[j].u==id) continue;
if(e[j].v==id) continue;
int fx=Find(e[j].u);
int fy=Find(e[j].v);
if(fx!=fy)
{
f[fx]=fy;
sz--;
}
}
printf("%d\n",sz-);
}
return ;
}
PAT (Advanced Level) 1013. Battle Over Cities (25)的更多相关文章
- PAT 解题报告 1013. Battle Over Cities (25)
		1013. Battle Over Cities (25) t is vitally important to have all the cities connected by highways in ... 
- PTA (Advanced Level) 1013 Battle Over Cities
		Battle Over Cities It is vitally important to have all the cities connected by highways in a war. If ... 
- 【PAT甲级】1013 Battle Over Cities (25 分)(并查集,简单联通图)
		题意: 输入三个整数N,M,K(N<=1000,第四个数据1e5<=M<=1e6).有1~N个城市,M条高速公路,K次询问,每次询问输入一个被敌军占领的城市,所有和该城市相连的高速公 ... 
- PAT 甲级 1013 Battle Over Cities (25 分)(图的遍历,统计强连通分量个数,bfs,一遍就ac啦)
		1013 Battle Over Cities (25 分) It is vitally important to have all the cities connected by highway ... 
- 1013 Battle Over Cities (25分) DFS  |  并查集
		1013 Battle Over Cities (25分) It is vitally important to have all the cities connected by highways ... 
- 【PAT Advanced Level】1013. Battle Over Cities (25)
		这题给定了一个图,我用DFS的思想,来求出在图中去掉某个点后还剩几个相互独立的区域(连通子图). 在DFS中,每遇到一个未访问的点,则对他进行深搜,把它能访问到的所有点标记为已访问.一共进行了多少次这 ... 
- PAT Advanced 1013 Battle Over Cities (25) [图的遍历,统计连通分量的个数,DFS,BFS,并查集]
		题目 It is vitally important to have all the cities connected by highways in a war. If a city is occup ... 
- PAT A 1013. Battle Over Cities (25)【并查集】
		https://www.patest.cn/contests/pat-a-practise/1013 思路:并查集合并 #include<set> #include<map> ... 
- PAT甲题题解-1013. Battle Over Cities (25)-求联通分支个数
		题目就是求联通分支个数删除一个点,剩下联通分支个数为cnt,那么需要建立cnt-1边才能把这cnt个联通分支个数求出来怎么求联通分支个数呢可以用并查集,但并查集的话复杂度是O(m*logn*k)我这里 ... 
随机推荐
- ftp以及smb的配置
			linux下ftp服务的配置1,打开终端,cd /etc/vsftpd2 vi vsftpd.conf3 相关的都打开说明: anonymous_enable=YES //允许匿名 ... 
- C#在Json反序列化中处理键的特殊字符
			假设有如下Json 数据: 1.{ 2."id" : 1, 3."@value" : "this a @", 4."$p" ... 
- 使用jstl标签遍历双层的map(map下面的map)
			<c:forEach var="firstMap" items="${map}"> <c:forEach var="secondMa ... 
- 444A/CF
			题目链接[http://codeforces.com/problemset/problem/444/A] 题意:给出一个无向图,找出一个联通子图,定义密度#=v(顶点值的和)/e(边值的和). 条件: ... 
- linux下环境变量PS1设置
			PS1变量中提示符各项含义: \d :代表日期,格式为weekday month date,例如:Wed Dec 12 \H :完整的主机名称.例如:hostname是debian.linux \ ... 
- hdu 3342 Legal or Not(拓扑排序)
			Legal or Not Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total ... 
- HDU 1814 Peaceful Commission
			2-SAT,输出字典序最小的解,白书模板. //TwoSAT输出字典序最小的解的模板 //注意:0,1是一组,1,2是一组..... #include<cstdio> #include&l ... 
- linux中服务器定时程序设定
			服务器不重启的情况下定时自动重启apache及mysql服务,其实也大同小异.具体步骤如下: 一.每天的12点及16点重启apache及mysql服务 [root@www bin]# cd /opt ... 
- PHP开发利器zend studio常见问题解答
			1.如何将zend studio 9的默认GBK编码设置为其它编码,例如UTF-8? 选择window菜单->Preferences->General->Workspace,在界面当 ... 
- Android Studio 提示Error running app: No Android facet found for app
			错误解决办法如下: 可以通过以下几个步骤解决该问题: 1) 点击菜单File -> 选择Project Structure, 或使用快捷键 (Ctrl+Alt+Shift+S) 打开”Proje ... 
