-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathCAM5.cpp
More file actions
50 lines (47 loc) · 864 Bytes
/
CAM5.cpp
File metadata and controls
50 lines (47 loc) · 864 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<iostream>
#include<queue>
#include<string.h>
#include<stdio.h>
using namespace std;
int check[100005];
queue <int> q[100005];
void dfs(int x)
{
check[x]=1;
int size=q[x].size();
for(int i=0;i<size;i++)
{
int temp=q[x].front();
q[x].pop();
if(!check[temp])
dfs(temp);
}
}
int main()
{
int t,n,e,x,y,count;
cin>>t;
while(t--)
{
count=0;
memset(check,0,sizeof(check));
cin>>n>>e;
for(int i=0;i<e;i++)
{
cin>>x>>y;
q[x].push(y);
q[y].push(x);
}
for(int i=0;i<n;i++)
{
//<<i<<" "<<check[i]<<"\n";
if(!check[i])
{
check[i]=1;
dfs(i);
count++;
}
}
cout<<count<<"\n";
}
}