Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.72 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define TRACE(x) x
  6. #define WATCH(x) TRACE( cout << #x" = " << x << endl)
  7. #define PRINT(x) TRACE(printf(x))
  8. #define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
  9. #define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
  10.  
  11. #define all(v) (v).begin(), (v).end()
  12. #define rall(v) (v).rbegin(), (v).rend()
  13. #define sz(v) (int) (v).size()
  14. #define rep(i,a,b) for(int (i) = (a); (i) < (b); ++(i))
  15. #define pb push_back
  16. #define mp make_pair
  17.  
  18. using ll = long long;
  19. using vi = vector<int>;
  20. using pii = pair<int, int>;
  21. using pll = pair<ll, ll>;
  22.  
  23. constexpr int inf = 0x3f3f3f3f;
  24. constexpr ll MOD = 1000000007LL;
  25. constexpr double tol = 1e-8;
  26.  
  27. void buff() { ios::sync_with_stdio( false ); cin.tie(nullptr); }
  28.  
  29. vector< vector<int> > graph;
  30. vector< int > mark;
  31. int current_label = 0;
  32.  
  33. void explore( int node, int label )
  34. {
  35.     mark[node] = label;
  36.     for( const int& x : graph[node] )
  37.     {
  38.         if( mark[x] == -1 ) explore(x, label);
  39.     }
  40. }
  41.  
  42. int main()
  43. {
  44.     buff();
  45.     int n, m, p;
  46.     cin >> n >> m >> p;
  47.     graph.resize(n);
  48.     mark.assign(n, -1);
  49.  
  50.     for(int i = 0; i < m; ++i)
  51.     {
  52.         int a, b;
  53.         cin >> a >> b;
  54.         --a; --b;
  55.         // grafo com arestas bi-direcionais
  56.         graph[a].push_back( b );
  57.         graph[b].push_back( a );
  58.     }
  59.    
  60.     for(int i = 0; i < n; ++i)
  61.     {
  62.         if( mark[i] == -1 ) explore(i, ++current_label );
  63.     }
  64.    
  65.     for(int i = 0; i < p; ++i)
  66.     {
  67.         int a, b;
  68.         cin >> a >> b;
  69.         --a; --b;
  70.         if( mark[a] == mark[b] ) cout << "Lets que lets" << endl;
  71.         else cout << "Deu ruim" << endl;
  72.     }
  73.     return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement