Advertisement
math_rodrigues

Untitled

May 24th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define st first
  5. #define nd second
  6. #define mp make_pair
  7. #define pb push_back
  8. #define cl(x, v) memset((x), (v), sizeof(x))
  9. #define db(x) cerr << #x << " == " << x << endl
  10. #define dbs(x) cerr << x << endl
  11. #define _ << ", " <<
  12. #define gcd(x, y) __gcd((x), (y))
  13.  
  14. typedef long long ll;
  15. typedef long double ld;
  16. typedef pair<int, int> pii;
  17. typedef pair<int, pii> piii;
  18. typedef pair<ll, ll> pll;
  19. typedef vector<int> vi;
  20. typedef vector<vi> vii;
  21.  
  22. const ld EPS = 1e-9, PI = acos(-1.);
  23. const ll LINF = 0x3f3f3f3f3f3f3f3f, LMOD = 1011112131415161719ll;
  24. const int INF = 0x3f3f3f3f, MOD = 1e9+7;
  25. const int N = 1e3+5;
  26.  
  27. class Graph {
  28.     int n;
  29.     vector<vector<int>> adj;
  30.  
  31.     void dfs(int v, vector<bool> &vis) {
  32.         if (vis[v]) return;
  33.         vis[v] = true;
  34.  
  35.         for (int u : adj[v])
  36.             dfs(u, vis);
  37.     }
  38. public:
  39.     void set_nodes(int _n) {
  40.         n = _n;
  41.         adj.assign(n+1, vector<int>());
  42.     }
  43.  
  44.     void add_edge(int u, int v) {
  45.         adj[u].pb(v);
  46.         adj[v].pb(u);
  47.     }
  48.  
  49.     string check_state() {
  50.         vector<bool> vis;
  51.         for (int i = 1; i <= n; i++) {
  52.             vis.assign(n+1, false);
  53.             dfs(i, vis);
  54.  
  55.             for (i = 1; i <= n; i++)
  56.                 if (!vis[i])
  57.                     return "falha";
  58.         }
  59.         return "normal";
  60.     }
  61. };
  62.  
  63. int main() {
  64.     int e, l, t = 1;
  65.     Graph *g = new Graph();
  66.     while (cin >> e >> l, e+l) {
  67.         g->set_nodes(e);
  68.  
  69.         for (int i = 0; i < l; i++) {
  70.             int x, y; cin >> x >> y;
  71.             g->add_edge(x,y);
  72.         }
  73.         cout << "Teste " << t++ << endl;
  74.         cout << g->check_state() << endl;
  75.         cout << endl;
  76.     }
  77.     return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement