GCD Spanning Tree
题号:NC252838
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Given a connected undirected graph G consisting of n vertices and m edges, with each edge has a positive integer weight w_i .

In one operation, you can choose an edge and change its weight to any positive integer.

We define a spanning tree T of G is an x-spanning tree if the gcd (greatest common divisior) of the weights of all the edges in T is a multiple of the given number x (i.e.  is a divisor of the gcd) .

Colin wants to ask you that at least how many operations have been executed, there exists at least one x-spanning tree T of G .

For some secret reason there will be k independent queries, please note that every query is based on the initially given graph G (i.e. all operations of your answer have not been actually executed) .

Recall that the spanning tree T of the graph G is a subgraph which is a tree and contains all vertices of the graph G. In other words, it is a connected graph which contains n - 1 edges and can be obtained by removing some of the edges from G.

输入描述:

The first line contains three integers n, m, k \ (1 \le n, m,k \le 10^5) , representing the number of vertices and edges in G , and the number of queries.

For the following m lines, each line contains three integers u_i,v_i,w_i \ ( 1 \le u_i, v_i \le n, u_i\not = v_i, 1 \le w_i \le 10^6) , represents there is an edge in G connects vertices u_i and v_i and its weight is w_iIt's guaranteed that the graph is connected.

For the following k lines, each line contains an integer x_i \text{ }(1\le x_i \le 10^6), representing the i-th query.

输出描述:

The output should contains k lines.

For the i-th line, output a single integer, representing the minimum number of operations for the i-th query.
示例1

输入

复制
4 6 3
1 2 2
1 3 5
1 4 4
2 3 9
2 4 12
3 4 6
2
3
5

输出

复制
0
1
2