问什么错
查看原帖
问什么错
46820
Wall_breaker楼主2020/5/22 16:41
#include<bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
	x = 0;
	T f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -1;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	x *= f;
}
inline void d_read(double &x) {
	x = 0.0;
	int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -1;
	for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
	if (c == '.'){
		double num = 1.0;
		c = getchar();
		for (; isdigit(c); c = getchar()) x = x + (num /= 10) * (c ^ 48);
	}
	x *= f;
}

template <typename T>
inline void w(T x) {
	if (x > 9) w(x / 10);
	putchar(x % 10 + 48);
}
template <typename T>
inline void write(T x, char c) {
	if (x < 0){
		putchar('-');
		x = -x;
	}
	w(x);
	putchar(c);
}
struct info{
	int to, nex, val;
}l[50];
int m, len, head[105], dis[105];
long long v[105][105], f[105];
bool ou[105], st[105][105], us[105];
priority_queue <pair <int, int> > q;
inline int dij() {
	memset(us, false, sizeof(us));
	for (int i = 2; i <= m; i ++) dis[i] = 1e7;
	q.push(make_pair(0, 1));
	while(!q.empty()) {
		int d = q.top().second; q.pop();
		if (us[d]) continue; us[d] = true;
		for (int i = head[d]; i; i = l[i].nex) {
			int u = l[i].to;
			if (!ou[u] && dis[d] + l[i].val < dis[u]) {
				dis[u] = dis[d] + l[i].val;
				q.push(make_pair(-dis[u], u));
			}
		}
	}
	return dis[m];
}

int main() {
	int n, ki, d, LZZ, x, y, z;
	read(n); read(m); read(ki); read(LZZ);
	for (int i = 1; i <= LZZ; i ++) {
		read(x); read(y); read(z);
		l[++ len] = (info) {y, head[x], z};
		head[x] = len;
		l[++ len] = (info) {x, head[y], z};
		head[y] = len;
	}
	read(d);
	for (int i = 1; i <= d; i ++) {
		read(x); read(y); read(z);
		for (int j = y; j <= z; j ++) {
			st[j][x] = 1;
		}
	}
	for (int i = 1; i <= n; i ++) {
		memset(ou, false, sizeof(ou));
		for (int j = i; j <= n; j ++) {
			for (int k = 1; k <= m; k ++) {
				if (st[j][k]) ou[k] = true;
			}
			v[i][j] = dij();
		}
	}
	for (int i = 1; i <= n; i ++) {
		f[i] = v[1][i] * (long long)i;
		for (int j = 1; j < i; j ++) {
			f[i] = min(f[i], f[j] + v[j + 1][i] * (long long)(i - j) + (long long)ki);
		}
	}
	write(f[n], '\n');
	return 0;
}
2020/5/22 16:41
加载中...