Pagini recente » Cod sursa (job #1352981) | Cod sursa (job #500932) | Cod sursa (job #2802794) | Cod sursa (job #41160) | Cod sursa (job #2124712)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("dfs.in");
ofstream fout("dfs.out");
const int nMax = 100005;
int n, m, ans;
vector <int> L[nMax];
bool viz[nMax];
inline void Read()
{
fin >> n >> m;
for(int i = 1; i <= m; i++)
{
int x, y;
fin >> x >> y;
L[x].push_back(y);
}
}
inline void Dfs(int nod)
{
viz[nod] = true;
for(auto it : L[nod])
if(!viz[it])
Dfs(it);
}
inline void Solve()
{
int ans = 0;
for(int i = 1; i <= n; i++)
if(!viz[i])
ans++, Dfs(i);
fout << ans << "\n";
}
int main()
{
Read();
Solve();
fin.close();fout.close();
return 0;
}