Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <queue>
  4. #include <cstring>
  5. #include <vector>
  6. using namespace std;
  7.  
  8. const int MAX = 1001;
  9.  
  10. vector< int > G[MAX];
  11. int fire[MAX], win[2][MAX];
  12.  
  13. void bfs(int u) {
  14. queue< int > Q;
  15. Q.push(u);
  16. fire[u] = 1;
  17. while(!Q.empty()) {
  18. u = Q.front();
  19. Q.pop();
  20. int sz = G[u].size();
  21. int i, v;
  22. for(i = 0; i < sz; i++) {
  23. v = G[u][i];
  24. if(!fire[v]) {
  25. fire[v] = fire[u] + 1;
  26. Q.push(v);
  27. }
  28. }
  29. }
  30. }
  31.  
  32. int play(int pl, int u, int d) {
  33. int v, i, sz;
  34. if(win[pl][u] > -1) return win[pl][u];
  35. int ret, winnn;
  36. sz = G[u].size();
  37. winnn = 0;
  38. for(i = 0; i < sz; i++) {
  39. v = G[u][i];
  40. if(fire[v] >= d+1) {
  41. ret = play(pl^1, v, d+1);
  42. if(ret == pl) {
  43. winnn = 1;
  44. }
  45. }
  46. }
  47. if(winnn) return win[pl][u] = pl;
  48. else return win[pl][u] = pl^1;
  49. }
  50.  
  51. int main() {
  52. int n, e;
  53. int i, u, v;
  54. //freopen("in.txt", "r", stdin);
  55. scanf("%d%d", &n ,&e);
  56. for(i = 0; i < e; i++) {
  57. scanf("%d%d", &u, &v);
  58. G[u].push_back(v);
  59. G[v].push_back(u);
  60. }
  61. bfs(1);
  62. memset(win, -1, sizeof(win));
  63. printf("%s\n", (play(1,1,1) == 1? "Vladimir" : "Nikolay"));
  64. return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement