F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Assignment For Princess

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2248    Accepted Submission(s): 693
Special Judge


Problem Description
¡¡¡¡Long long ago, in the Kingdom Far Far Away, there lived many little animals. And you are the beloved princess who is marrying the prince of a rich neighboring kingdom. The prince, who turns out to be a handsome guy, offered you a golden engagement ring that can run computer programs!
¡¡¡¡The wedding will be held next summer because your father, the king, wants you to finish your university first.
¡¡¡¡But you did¡¯t even have a clue on your graduation project. Your terrible project was to construct a map for your kingdom. Your mother, the queen, wanted to make sure that you could graduate in time.
¡¡¡¡Or your wedding would have to be delayed to the next winter. So she told you how your ancestors built the kingdom which is called the Roads Principle:

¡¡¡¡1. Your kingdom consists of N castles and M directed roads.
¡¡¡¡2. There is at most one road between a pair of castles.
¡¡¡¡3. There won¡¯t be any roads that start at one castle and lead to the same one.
¡¡¡¡She hoped those may be helpful to your project. Then you asked your cousin Coach Pang (Yes, he is your troubling cousin, he always asks you to solve all kinds of problems even you are a princess.), the Minister of Traffic, about the castles and roads. Your cousin, sadly, doesn¡¯t have a map of the kingdom. Though he said the technology isn¡¯t well developed and it depends on your generation to contribute to the map, he told you the Travelers Guide, the way travelers describe the amazing road system:
¡¡¡¡1. No matter which castle you start with, you can arrive at any other castles.
¡¡¡¡2. Traveling on theM roads will take 1, 2, 3, ... ,M days respectively, no two roads need the same number of days.
¡¡¡¡3. You can take a round trip starting at any castle, visiting a sequence of castles, perhaps visiting some castles or traveling on some roads more than once, and finish your journey where you started.
¡¡¡¡4. The total amount of days spent on any round trip will be a multiple of three.
¡¡¡¡But after a month, you still couldn¡¯t make any progress. So your brother, the future king, asked your university to assign you a simpler project. And here comes the new requirements. Construct a map that satisfies both the Roads Principle and the Travelers Guide when N and M is given.
¡¡¡¡There would probably be several solutions, but your project would be accepted as long as it meets the two requirements.
Now the task is much easier, furthermore your fiance sent two assistants to help you.
¡¡¡¡Perhaps they could finish it within 5 hours and you can think of your sweet wedding now.
 

Input
¡¡¡¡The first line contains only one integer T, which indicates the number of test cases.
¡¡¡¡For each test case, there is one line containing two integers N, M described above.(10 <= N <= 80, N+3 <= M <= N2/7 )
 

Output
¡¡¡¡For each test case, first output a line ¡°Case #x:¡±, where x is the case number (starting from 1).
¡¡¡¡Then output M lines for each test case. Each line contains three integers A, B, C separated by single space, which denotes a road from castle A to castle B and the road takes C days traveling.
¡¡¡¡Oh, one more thing about your project, remember to tell your mighty assistants that if they are certain that no map meets the requirements, print one line containing one integer -1 instead.
¡¡¡¡Note that you should not print any trailing spaces.
 

Sample Input
1 6 8
 

Sample Output
Case #1: 1 2 1 2 3 2 2 4 3 3 4 4 4 5 5 5 6 7 5 1 6 6 1 8
 

Hint

ªêThe restrictions like N >= 10 will be too big for a sample. So the sample is just a simple case for the detailed formats of input and output,
and it may be helpful for a better understanding. Anyway it won¡¯t appear in actual test cases.
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-20 11:50:28, Gzip enabled