問題一覧 > 通常問題

No.1207 Graph X

レベル : / AI推定難易度 : 1550 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 139
作問者 : penguinman / テスター : kaage
お気に入りにしたユーザー ProblemId : 4847 / 自分の提出
問題文最終更新日: 2021-01-23 06:32:20
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
技術室奥プログラミングコンテスト#5 Day2 (順位表) の他の問題:

Problem Statement

Penguinman lives in the Kingdom of Paken.

The Kingdom of Paken consists of $N$ cities and $M$ roads, and each city is assigned a number from $1$ to $N$.

The $i$-th road bidirectionally connects city $x_i$ and city $y_i$, and its length is expressed using a certain integer $X$ that is at least $2$, as $X^{z_i}$. The lengths of the roads are pairwise distinct; specifically, $z_i<z_{i+1}$ holds for every $i\ (1\leq i\leq M-1)$. It is also guaranteed that any city can be reached from any other city by traveling along some roads.

In the Kingdom of Paken, the time spent on transportation has become a problem, and as part of a policy, it has become necessary to find the sum of the shortest distances between cities $i,j$ over all choices of $i,j\ (1\leq i<j\leq N)$.

However, the amount of data is enormous, and the people of the Kingdom of Paken were unable to compute it.

Since the policy will stall if things stay as they are, please find the sum on their behalf and output the remainder when it is divided by $10^9+7$.

Input

\(N\) \(M\) \(X\)
\(x_1\) \(y_1\) \(z_1\)
\(x_2\) \(y_2\) \(z_2\)
\(︙\)
\(x_M\) \(y_M\) \(z_M\)
  • $2≤N≤2×10^5$
  • $N-1≤M≤2×10^5$
  • $2≤X≤10^9$
  • $1≤x_i,y_i≤N$
  • $0≤z_i≤10^9$
  • $x_i≠y_i$
  • $z_i<z_{i+1}$
  • Any city can be reached from any other city by using some roads
  • All inputs are integers

Output

Output the answer on 1 line, followed by a newline.

Sample

Sample 1
Input
3 2 3
1 2 0
2 3 1
Output
8

The shortest distance from vertex $1$ to $2$ is $1$,
the shortest distance from vertex $2$ to $3$ is $3$,
and the shortest distance from vertex $1$ to $3$ is $4$,
so output their sum, $8$.

Sample 2
Input
5 5 5
1 4 3
2 4 4
3 5 7
2 3 8
2 3 10
Output
2660500

There may be $2$ or more roads connecting the same pair of cities.

Sample 3
Input
6 8 1000000
2 6 10
3 5 11
4 6 23
1 3 26
1 6 30
5 6 48
3 5 88
3 6 100
Output
524978526

Note that the output should be $\bmod 10^9+7$.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。