Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #include <bitset>
- #include <iostream>
- #include <stack>
- #include <queue>
- #include <set>
- #include <map>
- #include <string>
- #include <algorithm>
- using namespace std;
- struct V {
- int n, d, r;
- } v[1010];
- bool vcmp(V a, V b) { return a.d < b.d; }
- map<V*, vector<V*> > g;
- map<V*, bool > u;
- int n, m, a, b;
- int main() {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- scanf("%d%d", &n, &m);
- for (int i = 0; i < n; i++) {
- v[i].n = i;
- v[i].r = -1;
- u.insert(make_pair(&v[i], 0));
- }
- for (int i = 0; i < m; i++) {
- scanf("%d%d", &a, &b);
- a--; b--;
- if (g.find(&v[a]) == g.end()) {
- vector<V*> w;
- g.insert(make_pair(&v[a], w));
- }
- if (g.find(&v[b]) == g.end()) {
- vector<V*> w;
- g.insert(make_pair(&v[b], w));
- }
- g[ &v[a] ].push_back( &v[b] );
- g[ &v[b] ].push_back( &v[a] );
- }
- queue<V*> q;
- v[ 0 ].d = 0;
- q.push( &v[0] );
- u[ &v[0] ] = 1;
- while (!q.empty()) {
- V* va = q.front();
- q.pop();
- for (int i = 0; i < g[ va ].size(); i++) {
- V* vb = g[va][i];
- if (!u[ vb ]) {
- vb->d = va->d + 1;
- q.push( vb);
- u[ vb ] = 1;
- }
- }
- }
- sort(&v[0], &v[n], vcmp);
- for (int i = n - 1; i >= 0; i--) {
- V *va = &v[i];
- bool isgood = 0;
- for (int i = 0; i < g[ va ].size(); i++) {
- V *vb = g[va][i];
- if (vb->d > va->d && vb->r == 0) {
- isgood = 1;
- break;
- }
- }
- va->r = isgood;
- }
- printf("%s", v[0].r ? "Vladimir" : "Nikolay");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement