int main() { while (true) { int n, m, source; double v; if (scanf("%d %d %d %lf", &n, &m, &source, &v) == -1) break; --source; WeightedDirectedGraphAsEdgeList<WeightType> graph(n, m); for (int i = 0; i < m; ++i) { int a, b; double Rab, Cab, Rba, Cba; scanf("%d %d %lf %lf %lf %lf", &a, &b, &Rab, &Cab, &Rba, &Cba); --a; --b; graph.AddEdge(WeightedEdge<WeightType>(a, b, WeightType(Rab, Cab))); graph.AddEdge(WeightedEdge<WeightType>(b, a, WeightType(Rba, Cba))); } CurrencyBellmanFord SSSP(&graph, source, v); SSSP.Compute(); if (SSSP.ExistNegativeCycle()) { printf("YES\n"); } else if (SSSP.Distance(source) > v) { printf("YES\n"); } else { printf("NO\n"); } } return 0; }
param_type(const IntervalRange& intervals_arg, const WeightRange& weights_arg) : _intervals(boost::begin(intervals_arg), boost::end(intervals_arg)), _weights(boost::begin(weights_arg), boost::end(weights_arg)) { if(_intervals.size() < 2) { _intervals.clear(); _intervals.push_back(RealType(0)); _intervals.push_back(RealType(1)); _weights.push_back(WeightType(1)); } }
param_type(IntervalIter intervals_first, IntervalIter intervals_last, WeightIter weight_first) : _intervals(intervals_first, intervals_last) { if(_intervals.size() < 2) { _intervals.clear(); _intervals.push_back(RealType(0)); _intervals.push_back(RealType(1)); _weights.push_back(WeightType(1)); } else { _weights.reserve(_intervals.size() - 1); for(std::size_t i = 0; i < _intervals.size() - 1; ++i) { _weights.push_back(*weight_first++); } } }
param_type(const std::initializer_list<T>& il, F f) : _intervals(il.begin(), il.end()) { if(_intervals.size() < 2) { _intervals.clear(); _intervals.push_back(RealType(0)); _intervals.push_back(RealType(1)); _weights.push_back(WeightType(1)); } else { _weights.reserve(_intervals.size() - 1); for(std::size_t i = 0; i < _intervals.size() - 1; ++i) { RealType midpoint = (_intervals[i] + _intervals[i + 1]) / 2; _weights.push_back(f(midpoint)); } } }
/** * Constructs a @c param_type object, representing a distribution * that produces values uniformly distributed in the range [0, 1). */ param_type() { _weights.push_back(WeightType(1)); _intervals.push_back(RealType(0)); _intervals.push_back(RealType(1)); }