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.
INPUT
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.
CONSTRAINTS
T <= 10;
1 <= N <= 10^6;
N - 1 <= R <= min(10^7, (N * (N - 1) ) / 2));
1 <= K <= N;
0 <= S <= 10^6
OUTPUT
print "Yes" if the soldiers are placed optimally else print "No", (quotes are for clarity.)
SAMPLE
INPUT 2 3 2 2 1 2 2 3 1 2 2 0 4 5 2 1 4 1 2 1 3 4 2 3 4 2 1 3 0 OUTPUT No Yes
WARNING ==> Large input.
hide comments
sudhamsh_:
2021-12-13 06:07:49
Are the test cases broken , does it give wrong answer to correct solutions ?? |
|
shashwt:
2021-11-06 09:40:43
Stop glorification of invaders!! |
|
dante2305:
2021-11-06 07:51:56
If you read the comments, you will find out that the test cases are weak. That means code giving incorrect answers are getting accepted. Because the output logic is binary (Yes/No), correct code will get rejected.
|
|
psk_7:
2021-10-12 08:43:06
stop glorifying invaders !!! |
|
striver2:
2021-10-12 05:50:35
@als510only 1 soldier has to protect a city
|
|
rifat448:
2021-09-20 22:25:10
@aryan_27 the test case you given in the comment will have answer "No". |
|
aryan_27:
2021-09-20 09:53:18
What should be the output for this test case?
|
|
rahul_521:
2021-06-26 08:54:08
I have found many problems on SPOJ with very complex problem statements(complex in terms of the language used) and some of them have wrong test cases (like this question). please make changes! |
|
aj_254:
2021-06-18 07:13:26
You can get AC but question is accepting wrong solution. |
|
ken2k:
2021-05-20 14:37:28
why am i getting bad alloc?
|
Added by: | Prayank Mathur |
Date: | 2014-10-12 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All |
Resource: | own |