Test instructions
Given a direction graph, each edge has a weight, each time you can select a node and an integer, the weight of all the edges ending with V minus D,
Add the weights of all sides with the start of the V plus D
Finally, let the minimum value of all edges be negative and as large as possible.
Code
#include <stdio.h> #include <iostream> #include <algorithm> #include <cstring> #include < Vector> #include <queue>using namespace std;const int N = 1e3;const int inf = 0x3f3f3f3f;int Dist[n],inq[n],cnt[n] ; struct node{int v,w; Node (int v,int W): V (v), W (w) {};}; vector<node> g[n];void init (int N) {for (int i = 0; i<=n; i++) G[i].clear ();} BOOL SPFA (int n) {queue<int> q; Q.push (0); memset (inq,0,sizeof (INQ)); memset (cnt,0,sizeof (CNT)); memset (dist,inf,sizeof (Dist)); Dist[0] = 0; Inq[0] = 1; Cnt[0] = 1; while (!q.empty ()) {int u = q.front (); Q.pop (); Inq[u] = 0; for (int i = 0; I<g[u].size (); i++) {int v = g[u][i].v, w= g[u][i].w; if (Dist[v]>dist[u] + W) {Dist[v] = Dist[u] + W; if (!inq[v]) Q.push (v), inq[v] = 1; if (++cnt[v]>n) return true; }}} return false;} BOOL Test (int Mid,int N) {for (int i = 1; i<=n; i++) for (int j = 0; J<g[i].size (); j + +) G[I][J].W-=mid; int ret = SPFA (n); for (int i = 1, i<=n; i++) for (int j = 0; J<g[i].size (); j + +) G[I][J].W +=mid; return ret;} int main () {int v,e; while (~SCANF ("%d%d", &v,&e)) {init (V); int UB = 0; int U, V, W; for (int i = 0; i<e; i++) {scanf ("%d%d%d", &u,&v,&w); G[u].push_back (Node (v,w)); UB = max (W,UB); } for (int i = 1; i<=v; i++) G[0].push_back (node (i,0)); int L = 1, R = UB; if (test (L,V)) puts ("No solution"); else if (!test (ub+1,v)) puts ("Infinite"); else {while (l<r) {int mid = L + (r-l)/2; if (test (mid,v)) R = mid; else L = mid + 1; } printf ("%d\n", L-1); }} return 0;}
UVA 11478 (differential constraint + two points)