Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <iostream>
- #include <queue>
- #include <cstring>
- #include <vector>
- using namespace std;
- const int MAX = 1001;
- vector< int > G[MAX];
- int fire[MAX], win[2][MAX];
- void bfs(int u) {
- queue< int > Q;
- Q.push(u);
- fire[u] = 1;
- while(!Q.empty()) {
- u = Q.front();
- Q.pop();
- int sz = G[u].size();
- int i, v;
- for(i = 0; i < sz; i++) {
- v = G[u][i];
- if(!fire[v]) {
- fire[v] = fire[u] + 1;
- Q.push(v);
- }
- }
- }
- }
- int play(int pl, int u, int d) {
- int v, i, sz;
- if(win[pl][u] > -1) return win[pl][u];
- int ret, winnn;
- sz = G[u].size();
- winnn = 0;
- for(i = 0; i < sz; i++) {
- v = G[u][i];
- if(fire[v] >= d+1) {
- ret = play(pl^1, v, d+1);
- if(ret == pl) {
- winnn = 1;
- }
- }
- }
- if(winnn) return win[pl][u] = pl;
- else return win[pl][u] = pl^1;
- }
- int main() {
- int n, e;
- int i, u, v;
- //freopen("in.txt", "r", stdin);
- scanf("%d%d", &n ,&e);
- for(i = 0; i < e; i++) {
- scanf("%d%d", &u, &v);
- G[u].push_back(v);
- G[v].push_back(u);
- }
- bfs(1);
- memset(win, -1, sizeof(win));
- printf("%s\n", (play(1,1,1) == 1? "Vladimir" : "Nikolay"));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement