当前位置:网站首页>“蔚来杯“2022牛客暑期多校训练营2 Link with Game Glitch (spfa找正负环)
“蔚来杯“2022牛客暑期多校训练营2 Link with Game Glitch (spfa找正负环)
2022-07-25 06:07:00 【不吃土司边】
#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define eps 1e-10
#define gcd __gcd
#define pb push_back
#define PI acos(-1.0)
#define lowbit(x) (x)&(-x)
#define bug printf("!!!!!\n");
#define mem(x,y) memset(x,y,sizeof(x))
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef unsigned long long uLL;
const int maxn = 1e5+2;
const int INF = 1<<30;
const int mod = 1e9+7;
struct edge {
int v;
double w;
};
int n,m;
vector<edge> e[maxn];
int cnt[maxn], vis[maxn];
double dis[maxn];
bool spfa(int n,double x) {
// memset(dis, 63, sizeof(dis));
queue<int> q;
x=log(x);
// cout<<x<<endl;
for(int i=1;i<=n;i++) dis[i]=-1e9,cnt[i]=0,q.push(i),vis[i]=1;
// cout<<w+x<<endl;
while (!q.empty()) {
int u = q.front();
q.pop(), vis[u] = 0;
for (auto ed : e[u]) {
int v = ed.v;
double w = ed.w;
// cout<<w+x<<endl;
if (dis[v] < dis[u] + w + x) {
dis[v] = dis[u] + w + x;
cnt[v] = cnt[u] + 1;
if (cnt[v] >= n) {
// cout<<v<<" "<<"false"<<endl;
return false;
}
if (!vis[v]) q.push(v), vis[v] = 1;
}
}
}
return true;
}
void solve(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) e[0].push_back({
i,0});
for(int i=1;i<=m;i++){
int a,b,c,d;
scanf("%d%d%d%d",&a,&b,&c,&d);
e[b].push_back({
d,log(1.0*c/a)});
// cout<<log(1.0*c/a)<<endl;
}
// cout<<spfa(n,0.6)<<endl;
double l=0,r=1;
while(abs(r-l)>=eps){
double mid=(l+r)/2;
if(spfa(n,mid)) l=mid;
else r=mid;
}
printf("%0.6lf\n",l);
return;
}
int main()
{
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
// ios::sync_with_stdio(false);
int t = 1;
//scanf("%d",&t);
while(t--){
// printf("Case %d: ",cas++);
solve();
}
return 0;
}
边栏推荐
- sqlilabs less-28~less-8a
- Leetcode/ integer division
- R language ggpubr package ggarrange function combines multiple images and annotates_ Figure add annotation, annotation, annotation information for the combined image, and use the right parameter to ad
- 动态规划学习笔记
- Unity 模型简化/合并 一键式插件
- (2022牛客多校二)K-Link with Bracket Sequence I(动态规划)
- Softing pngate series gateway: integrate PROFIBUS bus into PROFINET network
- sqlilabs less-29
- Req.body in node.express is always undefind
- 剑指 Offer 32 - I. 从上到下打印二叉树
猜你喜欢
![Get URL of [url reference]? For the following parameters, there are two ways to get the value of the corresponding parameter name and convert the full quantity to the object structure](/img/78/2a4e9d49bee8ef839d9d86fc7c3c83.png)
Get URL of [url reference]? For the following parameters, there are two ways to get the value of the corresponding parameter name and convert the full quantity to the object structure
This is how the permission system is designed, yyds

Sword finger offer 45. arrange the array into the smallest number
![[ultra detailed diagram] FPN + mask RCNN](/img/ef/ddd62fe7e54074c134aa5ee4cc5840.png)
[ultra detailed diagram] FPN + mask RCNN
![(14) [driver development] configuration environment vs2019 + wdk10 write XP driver](/img/90/0d94d26be8128d77de65919763fda5.png)
(14) [driver development] configuration environment vs2019 + wdk10 write XP driver

NFT: how to improve rentable NFT (erc-4907)

Siggraph 2022 -- rendering iridescent rock dove neck feathers

Daily question brushing record (XXVIII)

Ffmpeg notes (I) fundamentals of audio and video

(Niuke multi School II) j-link with arithmetic progress (least square method / three points)
随机推荐
Android interview question: why do activities rebuild ViewModel and still exist—— Jetpack series (3)
Detailed explanation of arm instruction CMP
context must be a dict rather解决
Sword finger offer 32 - I. print binary tree from top to bottom
基于ISO13209(OTX)实现EOL下线序列
HTB-Devel
(2022牛客多校二)L-Link with Level Editor I(动态规划)
Era5 dataset description
HTB-Beep
An SQL execution process
新时代生产力工具——FlowUs 息流全方位评测
10. Rendering Basics
R language obtains the data row where the nth maximum value of the specified data column is located in the data.table data
日期(DAY 76)
Amazoncaptcha 95%成功率绕过亚马逊IP验证码
What does PK, NN, Qu, B, UN, ZF, AI, G mean when creating tables in MySQL
sqlilabs less-28~less-8a
Softing pngate series gateway: integrate PROFIBUS bus into PROFINET network
What projects can make money online? Is it reliable to be we media?
Mechanism and principle of multihead attention and masked attention