Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define MAX 100
- using namespace std;
- vector<int> grafo[MAX];
- int marc[MAX];
- int tamComp;
- void dfs (int v){
- tamComp++;
- marc[v] = 1;
- for (int i = 0; i < grafo[v].size(); i++){
- int viz = grafo[v][i];
- if (marc[viz] == 0){
- dfs(viz);
- }
- }
- }
- int main (){
- int n, m; scanf("%d %d", &n, &m);
- for (int i = 1; i <= m; i++){
- int a, b; scanf("%d %d", &a, &b);
- grafo[a].push_back(b);
- grafo[b].push_back(a);
- }
- int nComp = 0;
- int maxTamComp = 0;
- for (int i = 0; i < n; i++){
- if (marc[i] == 0){
- nComp++;
- tamComp = 0;
- dfs(i);
- if (tamComp > maxTamComp){
- maxTamComp = tamComp;
- }
- }
- }
- printf("numero de componentes:%d tamanho maximo de uma componente: %d", nComp, maxTamComp);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement