• [1546] Teacher's Problem

  • 时间限制: 2000 ms 内存限制: 262144 K
  • 问题描述
  • One day my teacher gave me a problem to solve. I was given N unique names and each name has a value. Name is a string consisting of lowercase Latin letters with length less than 10. Value is a positive integer less than 100. Initially these names are sorted in lexicographic order. Now if the j-th name is the prefix of the i-th name and has the max length, j is the father of i. Then numbers 1 to N form a tree. From leaf to root, each son's value should be added to father's value. After I added these values, my teacher ask me to show all these values.

    Can you help me with the problem?

  • 输入
  • First line there is an integer T (T < 20) following T test cases.
    For each test case, first line is an integer N (0 < N <= 10^5), second line is N names, third line is N values.
    Names and values are separate by a space. There is no space at the end of line.
    Names are all unique and are given in Lexicographic order.
  • 输出
  • For each test case, please output one line with N integers. The i-th integer is the i-th value after added.
    Please do not output a space at the end of line.
  • 样例输入
  • 2
    3
    a ab ac
    5 10 15
    5
    a ab abb ac b
    5 10 100 15 6
  • 样例输出
  • 30 10 15
    130 110 100 15 6
  • 提示
  • Huge input, scanf is recommended.
  • 来源
  • zzxchavo @HEU 
  • 操作

显示春菜