|
||||||||||
Cyclic TourTime Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/65535 K (Java/Others)Total Submission(s): 3834 Accepted Submission(s): 1981 Problem Description There are N cities in our country, and M one-way roads connecting them. Now Little Tom wants to make several cyclic tours, which satisfy that, each cycle contain at least two cities, and each city belongs to one cycle exactly. Tom wants the total length of all the tours minimum, but he is too lazy to calculate. Can you help him? Input There are several test cases in the input. You should process to the end of file (EOF). The first line of each test case contains two integers N (N ¡Ü 100) and M, indicating the number of cities and the number of roads. The M lines followed, each of them contains three numbers A, B, and C, indicating that there is a road from city A to city B, whose length is C. (1 ¡Ü A,B ¡Ü N, A ¡Ù B, 1 ¡Ü C ¡Ü 1000). Output Output one number for each test case, indicating the minimum length of all the tours. If there are no such tours, output -1. Sample Input
Sample Output
Hint In the first sample, there are two cycles, (1->2->3->1) and (6->5->4->6) whose length is 20 + 22 = 42. Author RoBa@TJU Source | ||||||||||
|