当前位置:网站首页>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;
}
边栏推荐
- 修改px4飞控的系统时间
- 数据手册中的词汇
- 使用nodejs完成判断哪些项目打包+发版
- Receive user input, height BMI, BMI detection small business entry case
- Yunna | work order management measures, how to carry out work order management
- docker 方法安装mysql
- Your cache folder contains root-owned files, due to a bug in npm ERR! previous versions of npm which
- AcWing 346. Solution to the problem of water splashing festival in the corridor (deduction formula, minimum spanning tree)
- How to manage distributed teams?
- AcWing 1148. 秘密的牛奶运输 题解(最小生成树)
猜你喜欢

Your cache folder contains root-owned files, due to a bug in npm ERR! previous versions of npm which

一起看看matlab工具箱内部是如何实现BP神经网络的

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

云呐|工单管理软件,工单管理软件APP

Dark horse notes - create immutable sets and streams

According to the analysis of the Internet industry in 2022, how to choose a suitable position?

MySQL script batch queries all tables containing specified field types in the database

【信号与系统】

Set WordPress pseudo static connection (no pagoda)

Today's question -2022/7/4 modify string reference type variables in lambda body
随机推荐
子网划分、构造超网 典型题
Set WordPress pseudo static connection (no pagoda)
Go zero micro service practical series (IX. ultimate optimization of seckill performance)
设置Wordpress伪静态连接(无宝塔)
Gazebo的安装&与ROS的连接
C language instance_ two
2022 Google CTF SEGFAULT LABYRINTH wp
Use nodejs to determine which projects are packaged + released
golang 基础 —— 数据类型
Taro中添加小程序 “lazyCodeLoading“: “requiredComponents“,
云呐|工单管理办法,如何开展工单管理
What does front-end processor mean? What is the main function? What is the difference with fortress machine?
编译命令行终端 swift
AcWing 1142. 繁忙的都市 题解(最小生成树)
The difference between Tansig and logsig. Why does BP like to use Tansig
安全保护能力是什么意思?等保不同级别保护能力分别是怎样?
C # method of calculating lunar calendar date 2022
AcWing 345. 牛站 题解(floyd的性质、倍增)
新工作感悟~辞旧迎新~
Add the applet "lazycodeloading": "requiredcomponents" in taro,