This summer's heat wave and drought unleashed devastating wildfires all across the Earth. Of course, a tiny country on the island "Yars and Eva" is also affected by this ecological disaster. Thanks to the well-organized actions of rescuers, all the citizens were evacuated to the nearby planets on a spaceship.
To save the country, a small fire robot was left on its territory. He managed to extinguish fire in all cities except the capital before running out of liquid. The robot can't extinguish fire anymore, so the country is still in danger at the moment.
There are n cities in the country connected by m two-way roads. Each road connects a pair of cities. There is at most one road between any pair of cities. The cities are numbered from 1 to n, with capital having the number 1.
The fire spreads very quickly. On the very first day only the capital is on fire. But with every subsequent day, the fire devours all the cities connected by a road with the cities that are already on fire. Once the fire gets to a certain city, this city will continue to stay on fire till the very end.
The robot can't extinguish the fire anymore and there are no other means of firefighting left in the country, so obviously the country is going to be burned down to the ground. And you don't have to be a hero and save it. The key thing is that the robot is going to be destroyed by fire as well, and you need to figure out who will actually pay for the loss of government property.
Two pilots, Nikolay and Vladimir, are on Earth's natural satellite. They alternately take turns controlling the robot. The pilots alternate each day. Robot's speed is equal to the speed of fire, so the robot can get to the neighboring city in a day. Each pilot does not want the robot to be destroyed on his turn. For such a valuable loss they will have to pay a huge fee to the government.
On the first day the robot is located in the capital. Nikolay controls the robot on the first day. Thus, Nikolay controls the robot on the days with odd numbers, and Vladimir controls it on the days with even numbers. Taking turn, a pilot has to move the robot from the current city to any city connected by a road with the current one. If a pilot moves the robot to a city which is on fire, the robot is destroyed.
You task is to figure out who will pay the fine for the destroyed robot, assuming both pilots act optimally.
The first line of input contains the amount of cities n and the amount of roads m in the country (2 ≤ n ≤ 1000, n - 1 ≤ m ≤ 1000). The following m lines contain description of the roads: a, b — indices of the cities connected by roads (1 ≤ a ≤ n, 1 ≤ b ≤ n, a ≠ b). The roads are bidirectional. No pair of cities will be connected by more than one road. There will be a path between any two cities.
Output the name of the pilot who will pay the fine, assuming both pilots act optimally ("Nikolay" — if it is Nikolay, "Vladimir" — if it is Vladimir).
4 3 1 2 1 3 2 4
Vladimir
4 4 1 2 1 3 2 4 3 4
Nikolay
4 5 1 2 1 3 2 4 3 4 2 3
Nikolay
In the first sample test, an optimal strategy for Nicolay is to send the robot to the city 3 on the first day. Vladimir then will be forced to send the robot back to the capital, so the robot will be destroyed and Vladimir will have to pay.
题意:有n个点,m条无向边,棋子在点1,一人走一步,只能走到直接关联的点,然后点1着火了,每次从1开始扩散,与着火点直接关联的点都会着火,而且不会灭,谁往火力走谁输。
思路:
ac代码:
#include <bits/stdc++.h>
using namespace std;
const int MAXN=1010;
int x,y;
int son[MAXN],color[MAXN],peo[MAXN];
vector <int> mp[MAXN];
void Init()
{
for(int i=1;i<=x;i++)
{
color[i]=MAXN;
mp[i].clear();
son[i]=0;
peo[i]=0;
}
}
void make_color()
{
queue <int> que;
que.push(1);
color[1]=0;
peo[1]=0;
int pos,now;
while(!que.empty())
{
pos=que.front();
que.pop();
int len=mp[pos].size();
for(int i=0;i<len;i++)
{
now=mp[pos][i];
if(color[now]>color[pos])
{
son[pos]++;
peo[now]=!peo[pos];
if(color[now]==MAXN)
que.push(now);
color[now]=color[pos]+1;
}
}
}
}
int solve(int pos)
{
if(son[pos]==0)
return peo[pos];
int len=mp[pos].size();
int ans=0;
for(int i=0;i<len;i++)
{
if(color[mp[pos][i]]>color[pos])
ans+=solve(mp[pos][i]);
}
if(!peo[pos])
{
if(ans)
return 1;
else
return 0;
}
else
{
if(ans==son[pos])
return 1;
else
return 0;
}
}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int m,n;
while(cin>>x>>y)
{
Init();
while(y--)
{
cin>>n>>m;
mp[n].push_back(m);
mp[m].push_back(n);
}
make_color();
if(solve(1))
printf("Vladimir\n");
else
printf("Nikolay\n");
}
}