AtCoder Beginner Contest 399
G
Colorful Spanning Tree
AtCoder
⌀ 3625
原题
翻译中…

Problem Statement

翻译中…

You are given a connected undirected graph with $N$ vertices and $M$ edges, where the vertices are labeled $1$ to $N$. The graph does not contain self-loops, but it may contain multi-edges. Each edge has a color, and the $i$-th edge has a color $c_i$ ($1 \leq c_i \leq C$) and connects vertices $u_i$ and $v_i$. Also, a sequence $A = (A_1, A_2, \dots, A_C)$ is given.

翻译中…

Among the spanning trees of this graph, those satisfying the following condition are called colorful spanning trees:

翻译中…
  • For every integer $i$ such that $1 \leq i \leq C$, the number of edges of color $i$ included in the spanning tree is at most $A_i$.
翻译中…

Find the number of integer pairs $(L, R)$ with $1 \leq L \leq R \leq C$ that satisfy the following condition:

翻译中…
  • There exists a colorful spanning tree $T$ such that every edge in $T$ has a color $c$ with $L \leq c \leq R$.
翻译中…

Constraints

翻译中…
  • $2 \leq N \leq 150$
  • $N - 1 \leq M \leq \min\left(\frac{C N (N-1)}{2}, 5 \times 10^5\right)$
  • $1 \leq C \leq 300$
  • $1 \leq A_i \leq N-1$
  • $\sum_{i=1}^C A_i \leq 300$
  • $1 \leq u_i < v_i \leq N$
  • $1 \leq c_i \leq C$
  • If $i \neq j$, then $(u_i, v_i, c_i) \neq (u_j, v_j, c_j)$
  • The given graph is connected.
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N M C
A_1 A_2 \dots A_C
u_1 v_1 c_1
u_2 v_2 c_2
\vdots
u_M v_M c_M

翻译中…

Output

翻译中…

Print the number of integer pairs $(L, R)$ with $1 \leq L \leq R \leq C$ that satisfy the condition in the problem statement.

翻译中…

样例

Input #1
3 4 3
1 2 1
1 2 1
1 2 2
1 3 3
2 3 2
Output #1
4
For example, $(L, R) = (1, 2)$ satisfies the condition, because the spanning tree $T$ formed by the 1st and 4th edges is a colorful spanning tree, and all edges in $T$ have colors $c$ with $1 \leq c \leq 2$. There are four pairs $(L, R)$ that satisfy the condition: $(1, 2), (1, 3), (2, 2), (2, 3)$.
Input #2
5 10 6
2 2 4 1 1 1
1 3 2
1 5 4
2 3 3
1 4 1
4 5 1
4 5 3
2 4 1
1 4 3
1 3 4
1 2 5
Output #2
11
Input #3
10 20 5
2 4 4 6 4
5 9 1
4 5 2
2 8 5
8 9 4
1 10 5
8 10 1
8 9 5
4 8 2
4 10 4
5 8 3
5 9 5
6 10 2
3 5 4
4 6 1
3 4 3
7 9 3
5 7 1
1 3 3
1 8 5
5 10 4
Output #3
2
题目信息
题号
abc399_g
时间限制
6 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。