社区讨论

90 pts 求卡常

P1768天路参与者 2已保存回复 5

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
4 条
当前快照
1 份
快照标识符
@mlswljjf
此快照首次捕获于
2026/02/19 11:30
4 小时前
此快照最后确认于
2026/02/19 15:32
10 秒钟前
查看原帖
CPP
#include <bits/stdc++.h>
using namespace std;
const int N = 20010;
const double EPS = 1e-5;
struct node{
	int nxt, v, p;
};
int n, m, p[N], sum[N];
double dis[N];
bool vis[N];
vector<node> g[N];
queue<int> q;
inline int read(){
	int res = 0, f = 1;
	char c = getchar();
	while (c < '0' || c > '9'){
		if (c == '-') f = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9'){
		res = res * 10 + c - '0';
		c = getchar();
	}
	return res * f;
}
bool spfa(double mid){
	for(int i = 1; i <= n; i++){
		dis[i] = 0;
		sum[i] = 0;
		vis[i] = true;
		q.push(i);
	}
	while (!q.empty()){
		int x = q.front();
		q.pop();
		vis[x] = 0;
		for (int i = 0; i < g[x].size(); i++){
			int y = g[x][i].nxt; double yy = g[x][i].p * mid - g[x][i].v;
			if (dis[y] > dis[x] + yy){
				dis[y] = dis[x] + yy;
				sum[y]++;
				if (!vis[y]) q.push(y), vis[y] = 1;
				if (sum[y] > n) return 1;
			}
		}
	}
	return 0;
}
int main(){
	n = read(), m = read();
	for (int i = 1; i <= m; i++){
		int x = read(), y = read(), v = read(), p = read();
		g[x].push_back(node{y, v, p});
	} 
	double l = 0, r	= 200, ans = -1;
	while (l <= r - EPS){
		double mid = (l + r) / 2;
		if (spfa(mid)) ans = mid, l = mid;
		else r = mid;
	}
	if (ans < 0) puts("-1");
	else printf("%.1lf", ans);
	return 0;
}
TLE on #8
讨论版有邪门卡常我不认可。
CPP
if(ci[y]>20)
{
  return 1;
}

回复

5 条回复,欢迎继续交流。

正在加载回复...