当前位置:网站首页>"Wei Lai Cup" 2022 Niuke summer multi school training camp 2 d.[link with game glitch] two point answer +spfa ring
"Wei Lai Cup" 2022 Niuke summer multi school training camp 2 d.[link with game glitch] two point answer +spfa ring
2022-07-26 01:30:00 【HeartFireY】
D.Link with Game Glitch
Topic analysis
Yes m m m A recipe , Each recipe can be used k × a i k \times a_i k×ai individual b i b_i bi Raw material generation k × c i k \times c_i k×ci individual d i d_i di Grow raw materials . Now the request is k k k Multiply by a weight w w w, So that there is no situation that infinite items can be generated circularly among all recipes . Demand maximum m m m.
Obviously, it is necessary to generate infinite items , There needs to be a ring and the number of items generated along the ring is more than the original , That is, all edges on the ring have k ( c [ i ] − a [ i ] ) > 0 k(c[i] - a[i]) > 0 k(c[i]−a[i])>0 That is to say k c [ i ] a [ i ] > 1 k\frac{c[i]}{a[i]} > 1 ka[i]c[i]>1.
Since there may be multiple rings , We just need to ensure that the maximum ring will not be generated circularly . Obviously, you can do it with two answers .
Code
#include <bits/stdc++.h>
//#pragma gcc optimize(2)
#define double long double
#define endl '\n'
using namespace std;
const int N = 2e3 + 10, MOD = 1e9 + 7;
const double EPS = 1e-8;
struct node{
int v; double w; };
vector<node> g[N];
int n, m, cnt[N];
double dis[N];
bitset<N> vis;
bool check(double x){
queue<int> q;
x = -log(x);
vis.set();
memset(dis, 0, sizeof(dis));
memset(cnt, 0, sizeof(cnt));
for(int i = 1; i <= n; i++) q.emplace(i);
while(q.size()){
int u = q.front(); q.pop();
vis.reset(u);
for(auto nxt : g[u]){
int v = nxt.v;
double w = nxt.w;
if(dis[v] > dis[u] + w + x){
dis[v] = dis[u] + w + x;
cnt[v] = cnt[u] + 1;
if(cnt[v] > n) return true;
if(!vis[v]){
q.emplace(v);
vis.set(v);
}
}
}
}
return false;
}
inline void solve(){
cin >> n >> m;
for(int i = 1; i <= m; i++){
int a, b, c, d; cin >> a >> b >> c >> d;
g[b].emplace_back(node{
d, -log((1.0 * c) / a)});
}
double l = 0, r = 1;
for(int i = 1; i <= 300; i++){
double mid = (l + r) / 2;
if(check(mid)) r = mid;
else l = mid;
}
cout << l << endl;
}
signed main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout << fixed << setprecision(12);
int t = 1; //cin >> t;
while(t--) solve();
return 0;
}
边栏推荐
- C language enumeration types and unions
- Iftnews | suppose this is what the metauniverse looks like 20 years later
- Mysql_ Note2
- Google gson usage details
- SOC first project hello_ world
- Detailed explanation of at and crontab commands of RHCE and deployment of Chrony
- Is it safe to open an account for stock speculation through the online account manager?
- 【ICKIM 2022】第四届知识与信息管理国际会议
- U++ learning notes ustruct, uenum declaration and function library simple function implementation
- 【数据挖掘】生成模型和判别模型的区别及优缺点
猜你喜欢

What is informatization? What is digitalization? What are the connections and differences between the two?

"Yuanqi Cola" is not the end point, "China Cola" is

Fiddler5+ lightning simulator 4.0 settings for app packet capturing

Practice sharing of monorepo based on yarn1.x

Leetcode537. 复数乘法(可以,已解决)

Redis数据结构详解,结合书本

Google gson usage details

Basic version of Google browser debugging tool (I)

Handler消息机制-FWK层

Google Gson用法详解
随机推荐
PtGui pro12 vertical line correction
C language enumeration types and unions
Dot screen precautions
[secsha concept] original reverse supplement
格式化JS代码,调试JS代码
MDK compilation process and arm compilation tool chain
Fiddler5+ lightning simulator 4.0 settings for app packet capturing
Detailed explanation of at and crontab commands of RHCE and deployment of Chrony
【ICKIM 2022】第四届知识与信息管理国际会议
链表相关面试题
Mysql_ Note2
Handler消息机制-FWK层
The best way to practice Animation: cover transition
Easyrecovery15 data recovery software with high recovery rate and high download volume
"Yuanqi Cola" is not the end point, "China Cola" is
NLP introduction + practice: Chapter 4: using pytorch to manually realize linear regression
Codeforces Round #810 (Div. 2)A~C
Advanced C language (I) dynamic memory allocation
[CTF] crypto preliminary basic outline
C语言进阶(一)动态分配内存