Azrael
시간 제한7초메모리 제한512 MB
파이프로 숲에서 용기로 운반되는 주스의 총량을 최대로 한 뒤, c_i 곱하기 x_i의 제곱 합을 최소로 만드는 에너지를 출력한다.
문제
Gargamel is planning to clone his cat Azrael but for that he needs just one more ingredient: smurfberry juice. Gargamel has a number of containers, each of which can hold one litre of juice. Additionally there are some forests in which smurfberries grow (each forest has enough smurfberries to fill exactly one container with juice). Gargamel has already captured Smurfs living in each of the forests, now he wants to use them to gather smurfberries for him. Some forests are directly connected to some containers with pipes, which can be used to transport smurfberry juice. Unfortunately, controlling Smurfs takes energy. Smurfs in some forests are easier to control than in others. The more smurfberries Smurfs collect from one forest the harder they are to control. After extensive research Gargamel concluded that in order for Smurfs in forest to gather litres of smurfberry juice, he needs to use energy. Gargamel, being both very greedy and very lazy wizard, wants to collect as much smurfberry juice as he can and then minimize total amount of energy he uses. All those constraints made him so confused that he needs your help now.
입력
First line of input contains two integers and () denoting the number of forests and the number of juice containers respectively. Second line contains integers () -- the energy consumption coefficients for controlling the Smurfs in each of the forests. The next lines describe the pipes connecting forests and juice containers, each containing exactly p integers. The j-th integer in the i-th line is if the forest is connected to the container , or if there is no such connection.
출력
Output the minimum amount of energy Gargamel must use to collect as much smurfberry juice as possible. Your answer will be accepted if relative or absolute error is less than .