Advertisement
rdsedmundo

tarzan.cpp

May 17th, 2014
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <queue>
  4. #include <cstring>
  5.  
  6. using namespace std;
  7.  
  8. int n, grafo[1000][1000], vis[1000];
  9.  
  10. void bfs() {
  11.     queue<int> fila;
  12.     fila.push(0);
  13.  
  14.     while(!fila.empty()) {
  15.         int v = fila.front();
  16.         fila.pop();
  17.  
  18.         vis[v] = 1;
  19.         for(int i = 0; i < n; i++)
  20.             if(grafo[v][i] && i != v && !vis[i])
  21.                 fila.push(i), vis[i] = 1;
  22.     }
  23. }
  24.  
  25. int main() {
  26.  
  27.     memset(vis, 0, sizeof vis);
  28.     memset(grafo, 0, sizeof grafo);
  29.  
  30.     int d;
  31.     cin >> n >> d;
  32.  
  33.     int a[n][2];
  34.  
  35.     for(int i = 0; i < n; i++)
  36.         cin >> a[i][0] >> a[i][1];
  37.  
  38.     for(int i = 0; i < n; i++)
  39.         for(int j = i + 1; j < n; j++)
  40.             if((abs(a[i][0] - a[j][0]) * abs(a[i][0] - a[j][0]) + abs(a[i][1] - a[j][1]) * abs(a[i][1] - a[j][1])) <= (d * d))
  41.                 grafo[i][j] = grafo[j][i] = 1;
  42.  
  43.     bfs();
  44.  
  45.     for(int i = 0; i < n; i++)
  46.         if(!vis[i]) {
  47.             cout << "N" << endl;
  48.             return 0;
  49.         }
  50.  
  51.     cout << "S" << endl;
  52.  
  53.    return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement