Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Announcement
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register
We are currently conducting a survey on our services. We welcome you to participate in it. Please click here to enter the page.

Repairing Company
Time Limit:1000MS  Memory Limit:131072K
Total Submit:841 Accepted:150

Description

Lily runs a repairing company that services the Q blocks in the city. One day the company receives M repair tasks, the ith of which occurs in block pi, has a deadline ti on any repairman¡¯s arrival, which is also its starting time, and takes a single repairman di time to finish. Repairmen work alone on all tasks and must finish one task before moving on to another. With a map of the city in hand, Lily want to know the minimum number of repairmen that have to be assign to this day¡¯s tasks.

Input

The input contains multiple test cases. Each test case begins with a line containing Q and M (0 < Q ¡Ü 20, 0 < M ¡Ü 200). Then follow Q lines each with Q integers, which represent a Q ¡Á Q matrix ¦¤ = {¦Äij}, where ¦Äij means a bidirectional road connects the ith and the jth blocks and requires ¦Äij time to go from one end to another. If ¦Äij = −1, such a road does not exist. The matrix is symmetric and all its diagonal elements are zeroes. Right below the matrix are M lines describing the repairing tasks. The ith of these lines contains pi, ti and di. Two zeroes on a separate line come after the last test case.

Output

For each test case output one line containing the minimum number of repairmen that have to be assigned.

Sample Input

1 2
0
1 1 10
1 5 10
0 0

Sample Output

2

Source
POJ Monthly--2007.04.01, crazyb0y

[Submit]   [Go Back]   [Status]   [Discuss]

Home Page   Go Back  To top


All Rights Reserved 2003-2006 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator