1013. Battle Over Cities @ PAT (Advanced Level) Practise
来源:互联网 发布:影视类毕业设计 知乎 编辑:程序博客网 时间:2024/06/05 10:52
#include<iostream>using namespace std;struct edge{ int start; int end;};int father[1000];edge eg[1000000];int num;int findFather(int a){ if(father[a]==a) return a; return father[a]=findFather(father[a]);}void merge(int a,int b,int k){ if(a==k||b==k) return; int a_r,b_r; a_r=findFather(a); b_r=findFather(b); if(a_r==b_r) return ; father[a_r]=b_r; num--;//num-- after a merge}int main(){ int n,m,i,j,k; cin>>n>>m>>k; for(i=0;i<m;i++) cin>>eg[i].start>>eg[i].end; while(k--) { cin>>j; num=n-2;//one city is occupied. for(i=0;i<n;i++)//initialization father[i]=i; for(i=0;i<m;i++) merge(eg[i].start-1,eg[i].end-1,j-1); cout<<num<<endl; } return 0;}
- 1013. Battle Over Cities @ PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise 1013. Battle Over Cities (25)
- PAT (Advanced Level) Practise 1013. Battle Over Cities (25)
- PAT (Advanced Level) Practise 1013. Battle Over Cities (25)
- PAT (Advanced Level) Practise 1013 Battle Over Cities (25)
- PAT (Advanced Level) Practise 1013 Battle Over Cities
- 1013. Battle Over Cities (25)——PAT (Advanced Level) Practise
- 【PAT Advanced Level】1013. Battle Over Cities (25)
- [PAT (Advanced Level) ]1013.Battle Over Cities 解题文档
- 浙大 PAT Advanced level 1013. Battle Over Cities
- 【PAT】【Advanced Level】1013. Battle Over Cities (25)
- PAT (Advanced) 1013. Battle Over Cities (25)
- Pat(Advanced Level)Practice--1013(Battle Over Cities)
- PAT(Advanced Level) 1013 - Battle Over Cities(连通图)
- PAT (Advanced Level) 1013. Battle Over Cities (25) 并查集
- PAT 1013. Battle Over Cities
- PAT 1013. Battle Over Cities
- PAT 1013. Battle Over Cities
- 输出指定日期范围内,为"星期一"的所有日期
- EAS BOS 绑定QUERY的列表界面,代码添加合计脚
- .Net remoting, Webservice,WCF基础
- 使类的成员函数成为回调函数
- Ubuntu如何备份和恢复系统(1)
- 1013. Battle Over Cities @ PAT (Advanced Level) Practise
- 一个最简单的Objective C 程序
- 数据库的敲门砖~
- CF 327 A Flipping Game
- 作业调度框架 Quartz 学习笔记(一) -- HelloWorld !!!
- 自定义套打元数据
- Oracle 多行记录合并/连接/聚合字符串
- 如何使用Box2D和Cocos2D制作一款像Fruit Ninja一样的游戏
- javascript 获取选中的部分文本值