随笔分类 - 并查集
摘要:Problem DescriptionThere are so many different religions in the world today that it is difficult to keep track of them all. You are interested in finding out how many different religions students in your university believe in. You know that there are n students in your university (0 int father[50001
阅读全文
摘要:DescriptionAn earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computers, but an unexpected aftershock attacked, all computers in the network were all broken. The computers are repaired one by one, and the network gradually
阅读全文
摘要:Problem Description某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇。省政府“畅通工程”的目标是使全省任何两个城镇间都可以实现交通(但不一定有直接的道路相连,只要互相间接通过道路可达即可)。问最少还需要建设多少条道路?Input测试输入包含若干测试用例。每个测试用例的第1行给出两个正整数,分别是城镇数目N ( int father[1001],rank[1001];int find(int x)//寻找x的父节点{ if(x!=father[x]) father[x]=find(father[x]);//回溯时路径压缩 ...
阅读全文
摘要:Problem DescriptionMr Wang wants some boys to help him with a project. Because the project is rather complex, the more boys come, the better it will be. Of course there are certain requirements.Mr Wang selected a room big enough to hold the boys. The boy who are not been chosen has to leave the room
阅读全文
摘要:并查集是若干个不想交的集合,能够实现较快的合并和判断元素所在集合的操作,应用很多,如求无向图的连通分量个数等。并查集的精髓就是它的三种操作:初始化、查找、合并int father[MAX];//father[x]表示x的父节点int rank[MAX];//rank[x]表示x的秩void Make_set(int x){ father[x]=x; rank[x]=0;}int find(int x)//查找元素所在的父节点,回溯时压缩路径{ if(x!=father[x]) father[x]=find(father[x]); return father...
阅读全文
摘要:DescriptionSevere acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. To minimize transmission to others, the best strategy is to separate the suspects from others.In the Not-Spreading-Your-Sickness University (NSYSU), t
阅读全文