Well, the problem states that a relation A B means that the amount of alcohol in drink A (which must be a non-negative real number, I guess) is less than the amount of alcohol in B.
Comparison of reals is asymmetric.
Last edited by mf on Sun Aug 06, 2006 12:59 am, edited 1 time in total.
Yes, it's just a simple topological sort, but be careful when you count the degree of each node. I believe there will be the case when some of the edges are listed more than once in the input.
Case #1: Dilbert should drink beverages in this order: beer wine vodka.
Case #2: Dilbert should drink beverages in this order: apple-juice beer wine rum cachaca.
Case #3: Dilbert should drink beverages in this order: apple-juice wine vodka beer rum cachaca tequila whiskey martini gin
Case #1: Dilbert should drink beverages in this order: beer wine vodka.
Case #2: Dilbert should drink beverages in this order: apple-juice beer wine cachaca rum.
Case #3: Dilbert should drink beverages in this order: apple-juice beer rum cachaca gin martini wine whiskey vodka tequila.
maybe you sort the drinks by name , because the drinks on each level in sample is given by the order of input , but you output them in sorted order for example if B and A are in the same level and B is given before A in the input you should print B , A not A , B
Wei-Ming Chen wrote:Can someone tell me my outputs are legal or not?
No, they are not:
In the case there is no relation between two beverages Dilbert should start drinking the one that appears first in the input.
For example, in the 2nd sample case, there's no relation between rum and cachaca, but since rum appears earlier in the input, it should be drank before cachaca.
I had the same output when i did topological sort.
This is the key sentence:
In the case there is no relation between two beverages Dilbert should start drinking the one that appears first in the input.
It means that because juice is the first drink in the input that isn't preceeded by some other drink that has less alchohol, it comes first. Then, wine becomes the first drink in the input with the following property...