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

Harmonious Army

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1997    Accepted Submission(s): 731


Problem Description
Now, Bob is playing an interesting game in which he is a general of a harmonious army. There are $n$ soldiers in this army. Each soldier should be in one of the two occupations, Mage or Warrior. There are $m$ pairs of soldiers having combination ability. There are three kinds of combination ability. If the two soldiers in a pair are both Warriors, the army power would be increased by $a$. If the two soldiers in a pair are both Mages, the army power would be increased by $c$. Otherwise the army power would be increased by $b$, and $b = a / 4 + c / 3$, guaranteed that $4 | a$ and $3 | c$. Your task is to output the maximum power Bob can increase by arranging the soldiers' occupations.

Note that the symbol $a | b$ means that $a$ divides $b$, e.g. , $3|12$ and $8|24$.
 

Input
There are multiple test cases.

Each case starts with a line containing two positive integers $n(n \leq 500)$ and $m(m \leq 10^4)$.

In the following $m$ lines, each line contains five positive integers $u, \; v, \; a, \; b, \; c$ $(1 \leq u, v \leq n, u \neq v, 1 \leq a, c \leq 4 \times 10 ^6, b = a / 4 + c / 3)$, denoting soldiers $u$ and $v$ have combination ability, guaranteed that the pair $(u,v)$ would not appear more than once.

It is guaranteed that the sum of $n$ in all test cases is no larger than $5 \times 10^3$, and the sum of $m$ in all test cases is no larger than $5 \times 10^4$.
 

Output
For each test case, output one line containing the maximum power Bob can increase by arranging the soldiers' occupations.
 

Sample Input
3 2 1 2 8 3 3 2 3 4 3 6
 

Sample Output
12
 

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-04-26 19:53:07, Gzip enabled