Advertisement
Guest User

Fire in the Country 22.08.13

a guest
Aug 22nd, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.58 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <ctype.h>
  6. #include <bitset>
  7. #include <iostream>
  8. #include <stack>
  9. #include <queue>
  10. #include <set>
  11. #include <map>
  12. #include <string>
  13. #include <algorithm>
  14. using namespace std;
  15.  
  16. struct V {
  17.     int n, d, r;
  18. } v[1010];
  19.  
  20. bool vcmp(V a, V b) { return a.d < b.d; }
  21.  
  22. map<V*, vector<V*> > g;
  23. map<V*, bool > u;
  24. int n, m, a, b;
  25.  
  26.  
  27. int main() {
  28.     freopen("input.txt", "r", stdin);
  29.     freopen("output.txt", "w", stdout);
  30.        
  31.     scanf("%d%d", &n, &m);
  32.     for (int i = 0; i < n; i++) {
  33.         v[i].n = i;
  34.         v[i].r = -1;
  35.         u.insert(make_pair(&v[i], 0));
  36.     }
  37.  
  38.     for (int i = 0; i < m; i++) {
  39.         scanf("%d%d", &a, &b);
  40.         a--; b--;
  41.         if (g.find(&v[a]) == g.end()) {
  42.             vector<V*> w;
  43.             g.insert(make_pair(&v[a], w));
  44.         }
  45.         if (g.find(&v[b]) == g.end()) {
  46.             vector<V*> w;
  47.             g.insert(make_pair(&v[b], w));
  48.         }
  49.         g[ &v[a] ].push_back( &v[b] );
  50.         g[ &v[b] ].push_back( &v[a] );
  51.     }
  52.  
  53.     queue<V*> q;
  54.     v[ 0 ].d = 0;
  55.     q.push( &v[0] );
  56.     u[ &v[0] ] = 1;
  57.     while (!q.empty()) {
  58.         V* va = q.front();
  59.         q.pop();
  60.         for (int i = 0; i < g[ va ].size(); i++) {
  61.             V* vb = g[va][i];
  62.             if (!u[ vb ]) {
  63.                 vb->d = va->d + 1;
  64.                 q.push( vb);
  65.                 u[ vb ] = 1;
  66.             }
  67.         }
  68.     }
  69.     sort(&v[0], &v[n], vcmp);
  70.  
  71.     for (int i = n - 1; i >= 0; i--) {
  72.         V *va = &v[i];
  73.         bool isgood = 0;       
  74.         for (int i = 0; i < g[ va ].size(); i++) {
  75.             V *vb = g[va][i];
  76.             if (vb->d > va->d && vb->r == 0) {
  77.                 isgood = 1;
  78.                 break;
  79.             }
  80.         }
  81.         va->r = isgood;
  82.     }
  83.  
  84.     printf("%s", v[0].r ? "Vladimir" : "Nikolay");
  85.    
  86.     return 0;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement