Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. vector<int> adj[30];
  5. bool visited[30];
  6.  
  7. void dfs(int u) {
  8.     int v;
  9.     visited[u] = true;
  10.     for(int k = 0; k < adj[u].size(); ++k) {
  11.         v = adj[u][k];
  12.         if (!visited[v]) {
  13.             dfs(v);
  14.         }
  15.     }
  16. }
  17.  
  18. int cases;
  19. string v;
  20.  
  21. int main () {
  22.     cin >> cases;
  23.     getline(cin, v);
  24.     getline(cin, v);
  25.     while(cases--) {
  26.         getline(cin, v);
  27.         int times = v[0] - 64;
  28.         memset(visited, false, sizeof(visited));
  29.         getline(cin, v);
  30.         cout << v << "esse e V" << endl;
  31.         while(v != "") {
  32.             int v1 = v[0] - 65;
  33.             int v2 = v[1] - 65;
  34.             adj[v1].push_back(v2);
  35.             adj[v2].push_back(v1);
  36.             getline(cin, v);
  37.             cout << v;
  38.         }
  39.         bool check = false;
  40.         int cont = 0;
  41.         cout << "CONTADOR";
  42.         while(!check) {
  43.             check = true;
  44.             if (visited[cont]) {
  45.                 check = false;
  46.                 continue;
  47.             }
  48.             dfs(cont);
  49.             for (int i = 0; i < times && check; ++i) {
  50.                 if(!visited[i]) {
  51.                     check = false;
  52.                 }
  53.             }
  54.             cont++;
  55.         }
  56.         for (int i = 0; i < times; ++i) {
  57.             adj[i].clear();
  58.         }
  59.         cout << cont << endl;
  60.     }  
  61.     return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement