https://codeforc.es/contest/1366/problem/F
这玩意↑可以点开放大看
#include <bits/stdc++.h>
using namespace std;
#define int long long
void read (int &x) {
char ch = getchar(); x = 0;
while (!isdigit(ch)) ch = getchar();
while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
} const int N = 2038, mod = 1e9 + 7;
int n, m, q, res, mx, f[N][2];
int cnt, h[N], to[N << 1], nxt[N << 1], d[N << 1];
void add (int u, int v, int w) {
to[++cnt] = v, d[cnt] = w, nxt[cnt] = h[u], h[u] = cnt;
}
pair<int, int> t[N];
#define x first
#define y second
int Pow (int x, int y) {
int tmp = 1;
while (y) {
if (y & 1) tmp = tmp * x % mod;
x = x * x % mod, y >>= 1;
} return tmp;
}
signed main() {
// freopen ("data.in", "r", stdin);
read (n), read (m), read (q);
for (int i = 1, u, v, w; i <= m; ++i) {
read (u), read (v), read (w);
add (u, v, w), add (v, u, w); mx = max (mx, w);
}
for (int i = 2; i <= n; ++i) f[i][0] = -1;
for (int k = 1; k <= m; ++k) {
int p = (k & 1), tmp = 0;
for (int i = 1; i <= n; ++i) {
f[i][p] = -1;
for (int j = h[i]; j; j = nxt[j]) {
if (f[to[j]][p ^ 1] >= 0)
f[i][p] = max (f[i][p], f[to[j]][p ^ 1] + d[j]);
}
tmp = max (tmp, f[i][p]);
} res = (res + tmp) % mod;
}
for (int i = 1; i <= n; ++i) {
t[i].y = f[i][m & 1];
for (int j = h[i]; j; j = nxt[j])
t[i].x = max (t[i].x, d[j]);
}
int inv = Pow (2, mod - 2);
sort (t + 1, t + n + 1);
for (int i = 1; i <= n; ++i) {
int l = 1, r = q - m;
if (t[i].y == -1) continue;
for (int j = 1; j < i; ++j) {
int sx = t[i].x - t[j].x, sy = t[j].y - t[i].y;
if (!sy) continue;
int t = ceil (1.0 * sy / sx);
l = max (l, t);
}
for (int j = i + 1; j <= n; ++j) {
int sx = t[i].x - t[j].x, sy = t[j].y - t[i].y;
if (!sy) { r = 0; break; }
int t = ceil (1.0 * sy / sx) - 1;
r = min (r, t);
} if (l > r) continue;
res = (res + (r - l + 1) * ((t[i].y * 2 + t[i].x * (l + r)) % mod) % mod * inv % mod) % mod;
}
return printf ("%lld
", res), 0;
}