A undirected connected graph with n vertices and m edges. At the beginning, node 1 caught fire and it took one day for the fire to spread to its adjacent vertex. At the beginning, a robot was also located at Node 1, however, when the robot leaves, node 1 will catch fire. Vladimir and Nikolay take turns to control the robot. The robot can only move to another adjacent point in one day. In the end, whoever has to let the robot go to the fire will lose, output winner.
--> In the game in the search, the strategy is to let the fire go and enter the dead end. The opponent will not go any more in the next day (if a sub-state has a first hand, it will be defeated, so now this status is the first hand to win ).
F [I] indicates how many days the fire will take to reach the node I.
#include <cstdio>#include <cstring>#include <queue>using namespace std;const int maxn = 1000 + 10;int n, m, head[maxn], nxt[maxn<<1], u[maxn<<1], v[maxn<<1], ecnt, f[maxn];void init(){ for(int i = 1; i <= n; i++) head[i] = -1; ecnt = 0;}void addEdge(int uu, int vv){ u[ecnt] = uu; v[ecnt] = vv; nxt[ecnt] = head[uu]; head[uu] = ecnt; ecnt++;}void read(){ int i, uu, vv; for(i = 0; i < m; i++){ scanf("%d%d", &uu, &vv); addEdge(uu, vv); addEdge(vv, uu); }}void bfs(){ queue<int> qu; while(!qu.empty()) qu.pop(); f[1] = 1; qu.push(1); while(!qu.empty()){ int u = qu.front(); qu.pop(); for(int e = head[u]; e != -1; e = nxt[e]) if(!f[v[e]]){ f[v[e]] = f[u] + 1; qu.push(v[e]); } }}void fire(){ memset(f, 0, sizeof(f)); bfs();}bool dfs(int u){ for(int e = head[u]; e != -1; e = nxt[e]) if(f[v[e]] == f[u] + 1 && !dfs(v[e])) return 1; return 0;}int main(){ while(scanf("%d%d", &n, &m) == 2){ init(); read(); fire(); if(dfs(1)) printf("Vladimir\n"); else printf("Nikolay\n"); } return 0;}