kaggle-House Price Prediction

Prediction

07-27

Problem DescriptionnThere is a graph G=⟨VG,EG⟩ with |VG|=n and |EG|=m, and a magic tree T=⟨VT,ET⟩) rooted at 1, which contains m vertices.nnEach vertex of the magic tree corresponds to an edge in the original graph G and each edge occurs in the magic tree exactly once.nnEach query includes a set S(S⊆VT), and you should tell Mr. Frog the number of components in the modified graph G‘=(VG,E‘G), where E‘G is a set of edges in which every edge corresponds to a vertex v in magic tree T satisfying at least one of the following two conditions:nn∙v∈S.n∙v is an ancestor of some vertices in S.nnNote that the queries are independent, and namely one query will not influence another.n nnInputnThe input contains several test cases and the first line of the input data is an integer T, denoting the number of test cases.nnFor each test case, the first line contains two integers n and m(1≤n≤500,1≤m≤10000), where n is the number of vertices and m is the number of edges.nnThe second line contains m - 1 integers describing the magic tree, i-th integer represents the parent of the (i + 1)-th vertex.nnThen the following m lines describe the edges of the graph G. Each line contains two integers u and v indicating the two ends of the edge.nnThe next line contains only one integer q(1≤q≤50000), indicating the number of queries.nnThen the following q lines represent queries, i-th line represents the i-th query, which contains an integer ki followed by ki integers representing the set Si.nnIt is guarenteed that ∑qi=1ki≤300000.n nnOutputnFor each case, print a line "Case #x:", where x is the case number (starting from 1).nnFor each query, output a single line containing only one integer representing the answer, namely the number of components.n nnSample Inputn1n5 4n1 1 3n1 2n2 3n3 4n4 5n3n1 2n2 2 3n2 2 4n nnSample OutputnCase #1:n3n2n1

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试

关闭