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 Structures and Algorithms (English) - 7-18 Hashing - Hard Version(30 分)
Data Structures and Algorithms (English) - 7-18 Hashing - Hard Version(30 分)
222 0
Data Structures and Algorithms (English) - 7-18 Hashing - Hard Version(30 分)
|
机器学习/深度学习 算法
Data Structures and Algorithms (English) - 7-28 Review of Programming Contest Rules(30 分)
Data Structures and Algorithms (English) - 7-28 Review of Programming Contest Rules(30 分)
216 0
Data Structures and Algorithms (English) - 7-28 Review of Programming Contest Rules(30 分)
Data Structures and Algorithms (English) - 6-15 Iterative Mergesort(25 分)
Data Structures and Algorithms (English) - 6-15 Iterative Mergesort(25 分)
193 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 分)
105 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 分)
117 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 分)
97 0
Data Structures and Algorithms (English) - 6-2 Two Stacks In One Array(20 分)
Data Structures and Algorithms (English) - 6-2 Two Stacks In One Array(20 分)
145 0
Data Structures and Algorithms (English) - 7-9 Huffman Codes(30 分)
Data Structures and Algorithms (English) - 7-9 Huffman Codes(30 分)
103 0
Data Structures and Algorithms (English) - 6-14 Count Connected Components(20 分)
Data Structures and Algorithms (English) - 6-14 Count Connected Components(20 分)
145 0
Data Structures and Algorithms (English) - 6-13 Topological Sort(25 分)
Data Structures and Algorithms (English) - 6-13 Topological Sort(25 分)
112 0

热门文章

最新文章