-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathagentia.cpp
More file actions
42 lines (40 loc) · 672 Bytes
/
agentia.cpp
File metadata and controls
42 lines (40 loc) · 672 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
# include <fstream>
# include <algorithm>
# include <vector>
# define NR 105
using namespace std;
ifstream f("agentia.in");
ofstream g("agentia.out");
vector <int> v[NR];
int i,j,n,m,x,VV;
bool ap[NR];
void DFS (int k)
{
ap[k]=1;
for (int i=0; i<v[k].size(); ++i)
if (! ap[v[k][i]]) DFS (v[k][i]);
}
int main ()
{
f>>n;
for (i=1; i<=n; ++i)
{
f>>m;
for (j=1; j<=m; ++j)
{
f>>x;
v[i].push_back(x);
v[x].push_back(i);
}
}
for (i=1; i<=n; ++i)
{
if (! ap[i])
{
++VV;
DFS (i);
}
}
g<<VV<<"\n";
return 0;
}