Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- ifstream fin ("bazine.in");
- ofstream fout ("bazine.out");
- int n, viz[101], a[101][101], m, X, NrC;
- void citire()
- {
- int x , y;
- fin >> n >> m;
- while (fin >> x >> y)
- {
- a[x][y]=a[y][x]=1;
- }
- }
- void Dfs(int nod)
- {
- viz[nod]=NrC;
- for (int i=1; i<=n; i++)
- {
- if (a[nod][i]==1 and !viz[i])
- Dfs(i);
- }
- }
- void compcon()
- {
- for (int i=1; i<=n; i++)
- {
- if (viz[i]==0)
- {
- NrC++;
- Dfs(i);
- }
- }
- fout << NrC;
- }
- int main()
- {
- citire();
- compcon();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement