Data Structures and Algorithms (English) - 7-8 File Transfer(25 分)

简介: Data Structures and Algorithms (English) - 7-8 File Transfer(25 分)

题目链接点击打开链接

题目大意:略。

解题思路:略。

AC 代码

#include<bits/stdc++.h>#include<cmath>#define mem(a,b) memset(a,b,sizeof a)#define ssclr(ss) ss.clear(), ss.str("")#define INF 0x3f3f3f3f#define MOD 1000000007usingnamespacestd;
typedeflonglongll;
constintmaxn=10001;
unordered_set<int>ust;
intpre[maxn];
voidinit()
{
for(inti=0;i<maxn;i++) pre[i]=i;
}
intfind(intx)
{
returnpre[x]==x?x:pre[x]=find(pre[x]);
}
voidjoin(intx,inty)
{
intfx=find(x), fy=find(y);
if(fx!=fy) pre[fx]=fy;
}
intmain()
{
intn,a,b;
charop;
scanf("%d",&n);
init();
while(~scanf(" %c",&op) &&op!='S')
    {
scanf("%d%d",&a,&b);
if(op=='C')
        {
if(find(a)==find(b)) puts("yes");
elseputs("no");
        }
elseif(op=='I') join(a,b);
    }
for(inti=1;i<=n;i++) ust.insert(find(i));
if(ust.size()==1) puts("The network is connected.");
elseprintf("There are %d components.\n",ust.size());
return0;
}
目录
相关文章
|
数据可视化 数据挖掘 开发者
Data-Basic Statistical Descriptions of Data| 学习笔记
快速学习 Data-Basic Statistical Descriptions of Data。
103 0
Data-Basic Statistical Descriptions of Data| 学习笔记
Data Structures and Algorithms (English) - 6-15 Iterative Mergesort(25 分)
Data Structures and Algorithms (English) - 6-15 Iterative Mergesort(25 分)
166 0
Data Structures and Algorithms (English) - 6-8 Percolate Up and Down(20 分)
Data Structures and Algorithms (English) - 6-8 Percolate Up and Down(20 分)
85 0
Data Structures and Algorithms (English) - 7-12 How Long Does It Take(25 分)
Data Structures and Algorithms (English) - 7-12 How Long Does It Take(25 分)
87 0
|
存储 容器
Data Structures and Algorithms (English) - 7-18 Hashing - Hard Version(30 分)
Data Structures and Algorithms (English) - 7-18 Hashing - Hard Version(30 分)
192 0
Data Structures and Algorithms (English) - 7-18 Hashing - Hard Version(30 分)
Data Structures and Algorithms (English) - 7-9 Huffman Codes(30 分)
Data Structures and Algorithms (English) - 7-9 Huffman Codes(30 分)
81 0
Data Structures and Algorithms (English) - 6-13 Topological Sort(25 分)
Data Structures and Algorithms (English) - 6-13 Topological Sort(25 分)
86 0
Data Structures and Algorithms (English) - 6-7 Isomorphic(20 分)
Data Structures and Algorithms (English) - 6-7 Isomorphic(20 分)
104 0
Data Structures and Algorithms (English) - 7-10 Saving James Bond - Easy Version(25 分)
Data Structures and Algorithms (English) - 7-10 Saving James Bond - Easy Version(25 分)
67 0
Data Structures and Algorithms (English) - 6-14 Count Connected Components(20 分)
Data Structures and Algorithms (English) - 6-14 Count Connected Components(20 分)
114 0