

Power StationsTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2666 Accepted Submission(s): 783 Special Judge Problem Description There are N towns in our country, and some of them are connected by electricity cables. It is known that every town owns a power station. When a town¡¯s power station begins to work, it will provide electric power for this town and the neighboring towns which are connected by cables directly to this town. However, there are some strange bugs in the electric system ¨COne town can only receive electric power from no more than one power station, otherwise the cables will be burned out for overload. The power stations cannot work all the time. For each station there is an available time range. For example, the power station located on Town 1 may be available from the third day to the fifth day, while the power station on Town 2 may be available from the first day to the forth day. You can choose a subrange of the available range as the working time for each station. Note that you can only choose one subrange for each available range, that is, once the station stops working, you cannot restart it again. Of course, it is possible not to use any of them. Now you are given all the information about the cable connection between the towns, and all the power stations¡¯ available time. You need to find out a schedule that every town will get the electricity supply for next D days, one and only one supplier for one town at any time. Input There are several test cases. The first line of each test case contains three integers, N, M and D (1 <= N <= 60, 1 <= M <= 150, 1 <= D <= 5), indicating the number of towns is N, the number of cables is M, and you should plan for the next D days. Each of the next M lines contains two integers a, b (1 <= a, b <= N), which means that Town a and Town b are connected directly. Then N lines followed, each contains two numbers si and ei, (1 <= si <= ei <= D) indicating that the available time of Town i¡¯s power station is from the sith day to the eith day (inclusive). Output For each test case, if the plan exists, output N lines. The ith line should contain two integers ui and vi, indicating that Town i¡¯s power station should work from the uith day to viday (inclusive). If you didn¡¯t use this power station at all, set ui = vi = 0. If the plan doesn¡¯t exist, output one line contains ¡°No solution¡± instead. Note that the answer may not be unique. Any correct answers will be OK. Output a blank line after each case. Sample Input
Sample Output
Source  
