TouchStone
  Please Login
Login Sign Up
 Homepage  Problem Set  Examinations  Submissions  Discussions  Statistics
  • Home
  • Problem Set
  • P3075
  • Problem
  • P3075最小生成树8
    Limits : Time Limit : 10000 MS   Memory Limit : 262144 KB
    Judgment Tips : 1s,256MB
    Description

    给你一棵无根节点带权。每次给定k个节点,求他们的最小生成树(即将它们连通的最小代价)。

    Input Format

    第一行两个正整数n,q,表示节点数和提问数。
    接下来一行n个数表示点权。
    接下来n-1行每行两个数x,y表示一条边。
    接下来q行,每行第一个数k,接下来k个数为节点编号。

    Output Format

    每次提问输出答案。

    Sample Input

    3 4
    1 1 1
    1 2
    2 3
    1 1 
    2 1 2 
    2 1 3 
    3 1 2 3 

    Sample Output

    1
    2
    3
    3

    Hint

    n<=100000
    q<=100000
    所有k相加<=300000
    点权<=10000