当前位置:网站首页>AcWing 361. Sightseeing cow problem solution (SPFA seeking positive ring)
AcWing 361. Sightseeing cow problem solution (SPFA seeking positive ring)
2022-07-07 01:37:00 【Mr. Qiao Da】
AcWing 361. Sightseeing cows 
According to the formula in the figure , What this problem asks is to have a positive ring , So we are looking for the longest path , therefore if The judgement sentence in determines whether a longer boundary value can be found
#include<bits/stdc++.h>
using namespace std;
const int N = 1010, M = 5210;
int h[N], ne[M], e[M], w[M], idx;
int n, m;
double dist[N];
int wf[N];
bool st[N];
int cnt[N]; // Record edges
void add(int a, int b, int c){
e[idx] = b;
ne[idx] = h[a];
w[idx] = c;
h[a] = idx ++ ;
}
bool check(double mid){
memset(dist, 0, sizeof dist);
memset(st, 0, sizeof st);
memset(cnt, 0, sizeof cnt);
queue<int>q;
for(int i = 1; i <= n; i ++ ){
q.push(i);
st[i] = true;
}
while(q.size()){
int t = q.front();
q.pop();
st[t] = false;
for(int i = h[t]; ~i; i = ne[i]){
int j = e[i];
if(dist[j] < dist[t] + wf[t] - mid * w[i]){
// What is required is a positive ring , So it's the longest way
dist[j] = dist[t] + wf[t] - mid * w[i];
cnt[j] = cnt[t] + 1;
if(cnt[j] >= n) return true;
if(!st[j]){
q.push(j);
st[j] = true;
}
}
}
}
return false;
}
int main()
{
cin>>n>>m;
for(int i = 1; i <= n; i ++ ) cin>>wf[i];
memset(h, -1, sizeof h);
for(int i = 0; i < m; i ++ ){
int a, b, c;
cin>>a>>b>>c;
add(a, b, c);
}
double l = 0, r = 1e6;
while(r - l > 1e-4){
double mid = (l + r) / 2;
if(check(mid)) l = mid; // This value can , You can try to find a larger value
else r = mid; // This value is not good , Looking for a smaller value
}
printf("%.2lf\n", r);
return 0;
}
边栏推荐
- docker 方法安装mysql
- Yunna | work order management software, work order management software app
- Set WordPress pseudo static connection (no pagoda)
- Taro中添加小程序 “lazyCodeLoading“: “requiredComponents“,
- 百度飞将BMN时序动作定位框架 | 数据准备与训练指南 (上)
- How to evaluate load balancing performance parameters?
- Neon Optimization: performance optimization FAQ QA
- What does security capability mean? What are the protection capabilities of different levels of ISO?
- Your cache folder contains root-owned files, due to a bug in npm ERR! previous versions of npm which
- 机器学习:随机梯度下降(SGD)与梯度下降(GD)的区别与代码实现。
猜你喜欢

云呐-工单管理制度及流程,工单管理规范

MySQL script batch queries all tables containing specified field types in the database
![JS reverse -- ob confusion and accelerated music that poked the [hornet's nest]](/img/40/da56fe6468da64dd37d6b5b0082206.png)
JS reverse -- ob confusion and accelerated music that poked the [hornet's nest]

405 method not allowed appears when the third party jumps to the website

Yunna | work order management software, work order management software app

AI 从代码中自动生成注释文档

Body mass index program, entry to write dead applet project

Typical problems of subnet division and super network construction

百度飞将BMN时序动作定位框架 | 数据准备与训练指南 (下)

Appium基础 — Appium Inspector定位工具(一)
随机推荐
LeetCode:1175. Prime permutation
微信公众号发送模板消息
一起看看matlab工具箱内部是如何实现BP神经网络的
uva 1401 dp+Trie
子网划分、构造超网 典型题
Yunna | work order management software, work order management software app
免费白嫖的图床对比
Your cache folder contains root-owned files, due to a bug in npm ERR! previous versions of npm which
Byte P7 professional level explanation: common tools and test methods for interface testing, Freeman
2022 Google CTF SEGFAULT LABYRINTH wp
golang 基础 —— 数据类型
AcWing 904. 虫洞 题解(spfa求负环)
AcWing 1148. 秘密的牛奶运输 题解(最小生成树)
数据手册中的词汇
Spark TPCDS Data Gen
增加 pdf 标题浮窗
AcWing 1140. 最短网络 (最小生成树)
Set up [redis in centos7.x]
盒子拉伸拉扯(左右模式)
鼠标右键 自定义