AKBAR - Akbar , The great
All of us are familiar with the reign of the great mughal ruler , Akbar. He was always concerned with the prosperity and safety of the people . Therefore to safeguard his kingdom (which consisted of N cities) he wanted to place secret soldiers all over his kingdom so as to protect the people . But since his kingdom is very large therefore he wanted to place them in such a way that every city is protected by one and only one soldier.According to Akbar , this is the optimum placement.
As for these soldiers they can protect multiple cities according to their strengths.
The strength of a particular soldier is defined as the maximum distance upto which a guard can protect a city from its base city(base city is the city assigned to the guard). If there are 3 cities C1, C2 and C3 such that C1 C2 and C2 C3 are connected respectively, if a soldier with strength 1 is placed at C2 then all the cities C1, C2 and C3 are protected by that soldier.
Also the kingdom is connected with a network of secret two way roads for faster access only accessible to these soldiers. The length of any road on this network between any two cities is 1 kms .There are R such roads in the kingdom.
He had given this task to birbal to place the soldiers . Birbal didn't wanted to be a fool in front of the king , therefore took the job and placed M soldiers all over the kingdom but he was not very good at mathematics . But since he is very intelligent he somehow places the guards all over the kingdom and now turns to you (who is a genius mathematician ;) ) to check whether his placements are good or not.
Your task is to check if the placements of the soldiers are optimum or not.
The input consists of T test cases . Each test case then consists of 3 parts.The first line consists of N, R and M.
the next R lines consists of two numbers A and B denoting the two cities between which a road exists .
the next M lines consists of 2 numbers, city number K and strength S of that particular soldier.
=> strength 0 means it will only guard the city on which it is present .
=> assume every city is accesible from every other city .
T <= 10;
1 <= N <= 10^6;
N -1 <= R <= min( 10^7 , ( N * (N - 1) ) / 2) );
1 <= K <= N;
0 <= S <= 10^6
print "Yes" if the soldiers are placed optimumly else print "No". (quotes are for clarity)
3 2 2
4 5 2
WARNING ==> Large input.
good question , just take care that you are printing Yes not "YES" ...hahaha it cost me 5 wa
just make sure that each is gaurded by any one number of gaurds ...if even one city left ungaurded print no
ac in pypi2 0.78 sec. after 4 tle and 9 wa.. very tricky question language is very bad,,in python use deque during bfs for acLast edit: 2019-04-21 13:02:38
The problem statement is ambiguous. A city having no soldier should be protected by any no. of soldier and if a city has a soldier assigned to it then only that soldier should protect it.
I am getting WA. Tried all the test cases in comments. couldn't find the issue please help
The question is worded just fine. It's all the comments that say the question really wants something different that sowed doubts in my mind.
This question is very poorly worded(maybe intentionally) but it wasted a lot of time.
only bfs. dfs is worthless for some test case.
@manoj_0786 I think you have to follow Birbal's order sequentially, and, it's not necessary for a soldier to look after every city under his strength. What's necessary here is to see if all the cities here are being protected by sequentially placing the soldiers at mentioned cities.
ans must be no for this test case: