210. Beloved Sons
time limit per test: 0.25
memory limit per test: 65536
Once upon a time there lived a king and he had N sons. And the king wanted to marry his beloved sons on the girls that they did love. So one day the king asked his sons to come to his room and tell him whom do they love.
But the sons of the king were all young men so they could not tell exactly whom they did love. Instead of that they just told him the names of the girls that seemed beautiful to them, but since they were all different, their choices of beautiful girls also did not match exactly.
The king was wise. He did write down the information that the children have provided him with and called you, his main wizard.
"I want all my kids to be happy, you know," he told you, "but since it might be impossible, I want at least some of them to marry the girl they like. So please, prepare the marriage list."
Suddenly you recalled that not so long ago the king told you about each of his sons, so you knew how much he loves him. So you decided to please the king and make such a marriage list that the king would be most happy. You know that the happiness of the king will be proportional to the square root of the sum of the squares of his love to the sons that would marry the girls they like.
So, go on, make a list to maximize the king's happiness.
The first line of the input file contains N — the number of king's sons (1 ≤ N ≤ 400). The second line contains N integer numbers Ai ranging from 1 to 1000 — the measures of king's love to each of his sons.
Next N lines contain lists of king's sons' preferences — first Ki — the number of the girls the i-th son of the king likes, and then Ki integer numbers — the girls he likes (all potentially beautiful girls in the kingdom were numbered from 1 to N, you know, beautiful girls were rare in those days).
Output N numbers — for each son output the number of the beautiful girl he must marry or 0 if he must not marry the girl he likes.
Denote the set of sons that marry a girl they like by L, then you must maximize the value of
sqrt( sum(i from L, Ai2) )
1 3 2 4
4 1 2 3 4
2 1 4
2 1 4
2 1 4
2 1 0 4
|Resource:||Petrozavodsk Summer Trainings 2003
|Server time: 2016-05-28 08:51:07||Online Contester Team © 2002 - 2016. All rights reserved.|