Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin ("componenteconexe2.in");
- ofstream fout ("componenteconexe2.out");
- int n , a[105][105] , nrm , nrnod;
- bool viz[105];
- void DFS(int nod)
- {
- viz[nod] = true;
- nrnod++;
- for(int i = 1 ; i <= n ; i++)
- if(a[nod][i] == 1)
- nrm++;
- for(int i = 1 ; i <= n ; i++)
- if(viz[i] == 0 && a[nod][i] == 1)
- DFS(i);
- }
- int main()
- {
- int x , y , s = 0;
- fin >> n;
- while(fin >> x >> y)
- a[x][y] = a[y][x] = 1;
- for(int i = 1 ; i <= n ; i++)
- if(!viz[i])
- {
- nrm = nrnod = 0;
- DFS(i);
- nrm /= 2;
- s += (nrm - nrnod + 1);
- }
- fout << s << "\n";
- fin.close();
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement