CF925F.Parametric Circulation

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Vova has recently learned what a circulaton in a graph is. Recall the definition: let G=(V,E)G = (V, E) be a directed graph. A circulation ff is such a collection of non-negative real numbers fef_e (e∈Ee \in E), that for each vertex v∈Vv \in V the following conservation condition holds:

sumlimits_eindelta−(v)f_e=sumlimits_eindelta+(v)f_e\\sum\\limits\_{e \\in \\delta^{-}(v)} f\_e = \\sum\\limits\_{e \\in \\delta^{+}(v)} f\_e

where δ+(v)\delta^{+}(v) is the set of edges that end in the vertex vv, and δ−(v)\delta^{-}(v) is the set of edges that start in the vertex vv. In other words, for each vertex the total incoming flow should be equal to the total outcoming flow.

Let a lrlr-circulation be such a circulation ff that for each edge the condition le≤fe≤rel_e \leq f_e \leq r_e holds, where lel_e and rer_e for each edge e∈Ee \in E are two non-negative real numbers denoting the lower and upper bounds on the value of the circulation on this edge ee.

Vova can't stop thinking about applications of a new topic. Right now he thinks about the following natural question: let the graph be fixed, and each value lel_e and rer_e be a linear function of a real variable tt:

l\_e(t) = a\_e t + b\_e$$ $$r\_e(t) = c\_e t + d\_e

Note that tt is the same for all edges.

Let tt be chosen at random from uniform distribution on a segment [0,1][0, 1]. What is the probability of existence of lrlr-circulation in the graph?

沃瓦最近学习了图中“循环流”(circulation)的概念。回顾其定义:设 G=(V,E)G = (V, E) 是一个有向图。一个循环流 ff 是一组非负实数 fef_e(其中 e∈Ee \in E),满足对每个顶点 v∈Vv \in V,如下守恒条件成立:

∑e∈δ−(v)fe=∑e∈δ+(v)fe\sum\limits_{e \in \delta^{-}(v)} f_e = \sum\limits_{e \in \delta^{+}(v)} f_e

其中 δ+(v)\delta^{+}(v) 表示以顶点 vv 为终点的边集,δ−(v)\delta^{-}(v) 表示以顶点 vv 为起点的边集。换言之,对每个顶点,总流入量应等于总流出量。

称一个循环流 ff 为 lrlr-循环流,若对每条边 ee 均满足约束 le≤fe≤rel_e \leq f_e \leq r_e,其中对每条边 e∈Ee \in E,lel_e 和 rer_e 是两个非负实数,分别表示该边上循环流取值的下界与上界。

沃瓦无法停止思考这一新概念的应用。此刻他正考虑如下自然问题:图 GG 固定不变,且对每条边 ee,其上下界 lel_e 和 rer_e 均为实变量 tt 的线性函数:

l_e(t) = a_e t + b_e$$ $$r_e(t) = c_e t + d_e

注意:所有边共享同一个变量 tt。

设 tt 在区间 [0,1][0, 1] 上服从均匀分布,随机选取。问:图中存在 lrlr-循环流的概率是多少?

输入格式

The first line contains two integers nn, mm (1≤n≤10001 \leq n \leq 1000, 1≤m≤20001 \leq m \leq 2000).

Each of the next mm lines describes edges of the graph in the format ueu_e, vev_e, aea_e, beb_e, cec_e, ded_e (1≤ue,ve≤n1 \leq u_e, v_e \leq n, −104≤ae,ce≤104-10^4 \leq a_e, c_e \leq 10^4, 0≤be,de≤1040 \leq b_e, d_e \leq 10^4), where ueu_e and vev_e are the startpoint and the endpoint of the edge ee, and the remaining 4 integers describe the linear functions for the upper and lower bound of circulation.

It is guaranteed that for any t∈[0,1]t \in [0, 1] and for any edge e∈Ee \in E the following condition holds 0≤le(t)≤re(t)≤1040 \leq l_e(t) \leq r_e(t) \leq 10^4.

第一行包含两个整数 nn、mm(1≤n≤10001 \leq n \leq 1000,1≤m≤20001 \leq m \leq 2000)。

接下来的 mm 行每行描述图中的一条边,格式为 ueu_e、vev_e、aea_e、beb_e、cec_e、ded_e(其中 1≤ue,ve≤n1 \leq u_e, v_e \leq n,−104≤ae,ce≤104-10^4 \leq a_e, c_e \leq 10^4,0≤be,de≤1040 \leq b_e, d_e \leq 10^4),ueu_e 和 vev_e 分别为边 ee 的起点和终点,其余四个整数用于描述该边上流的上界与下界所对应的线性函数。

保证对任意 t∈[0,1]t \in [0, 1] 及任意边 e∈Ee \in E,均有 0≤le(t)≤re(t)≤1040 \leq l_e(t) \leq r_e(t) \leq 10^4。

输出格式

Print a single real integer — the probability of existence of lrlr-circulation in the graph, given that tt is chosen uniformly at random from the segment [0,1][0, 1]. Your answer is considered correct if its absolute difference from jury's answer is not greater than 10−610^{-6}.

输出一个实数——在 tt 于区间 [0,1][0, 1] 上均匀随机选取的前提下,图中存在 lrlr-环流的概率。若你的答案与标准答案的绝对误差不超过 10−610^{-6},则视为正确。

输入输出样例

  • 输入#1

    3 3
    1 2 0 3 -4 7
    2 3 -2 5 1 6
    3 1 0 4 0 4

    输出#1

    0.25

说明/提示

In the first example the conservation condition allows only circulations with equal values fef_e for all three edges. The value of circulation on the last edge should be 44 whatever tt is chosen, so the probability is

P(4 \\in \[3, -4t + 7\]~~\\&~~4 \\in \[-2t + 5, t + 6\]) = 0.25

在第一个例子中,守恒条件仅允许三条边上的环流值 fef_e 均相等。无论选择何种 tt,最后一条边上的环流值都必须为 44,因此所求概率为

P(4∈[3,−4t+7]  &  4∈[−2t+5,t+6])=0.25P(4 \in [3, -4t + 7]~~\&~~4 \in [-2t + 5, t + 6]) = 0.25

输入解题思路,AI测评打分。不知道怎么写?

首页