Well, we can see the graph theory part for the moment. Sort out the latest things.
// The shortest path // using stravoid Dijkstra () {memset (VIS, 0, sizeof (VIS); For (INT I = 1; I <= N; I ++) {d [I] =-1;} d [N] = 1; for (int K = 1; k <= N; k ++) {double maxv =-1; int x = N; For (INT I = 1; I <= N; I ++) if (! Vis [I] & D [I]> maxv) {maxv = d [x = I];} vis [x] = true; For (INT I = 1; I <= N; I ++) if (! Vis [I] & P [x] [I]> = 0) {If (d [I] =-1) d [I] = d [x] * P [x] [I]; else d [I] = max (d [I], d [x] * P [x] [I]) ;}}// Dijkstra + heapvoid Dijkstra (int * V) {memset (VIS, 0, sizeof (VIS); For (INT I = 1; I <= N; I ++) d [I] = inf; d [1] = 0; priority_queue <node> q; q. push (node (d [1], 1); While (! Q. empty () {node now = Q. top (); q. pop (); int x = now. b; If (vis [x]) continue; vis [x] = true; For (INT I = first [X]; I! = 0; I = NXT [I]) {If (d [V [I]> d [x] + W [I]) {d [V [I] = d [x] + W [I]; q. push (node (d [V [I], V [I]) ;}}// Bellman-fordvoid bellman_ford () {for (INT I = 0; I <m; I ++) d [I] = inf; d [0] = 0; For (INT I = 0; I <m; I ++) {for (Int J = 0; j <m; j ++) {for (int K = 0; k <m; k ++) if (Dist [J] [k] <inf) {If (d [J] <inf) {d [k] = min (d [K], d [J] + dist [J] [k]) ;}}} printf ("%. 2f \ n ", d [m-1]);} // spfavoid spfa (int * V, in T * D) {memset (VIS, 0, sizeof (VIS); For (INT I = 1; I <= N; I ++) d [I] = inf; d [x] = 0; queue <int> q; q. push (x); While (! Q. empty () {int u = Q. front (); q. pop (); vis [u] = false; For (INT I = first [u]; I! = 0; I = NXT [I]) {If (d [V [I]> d [u] + W [I]) {d [V [I] = d [u] + W [I]; If (! Vis [V [I]) {vis [V [I] = true; q. push (V [I]) ;}}}// Euler's and Euler's circuits // find the Euler's path and output path void DFS (INT now) {for (INT I = 0; I <E [now]. size (); I ++) {If (E [now] [I]. vis = 0) {e [now] [I]. vis = 1; DFS (E [now] [I]. v); ans. push (E [now] [I]. str) ;}}// network stream // label method // Ford-fulkersonvoid solve () {memset (flow, 0, sizeof (flow )); alpha [s] = inf; while (1) {// initialization label for (INT I = 1; I <= T; I ++) Pre [I] =-2; pre [s] =-1; // initialize the queue. The source node is in the column Qs = 0; Qe = 1; Q [QS] = s; // tag process while (QS <QE & Pre [T] =-2) {// The end is not labeled and the queue is not empty. Int v = Q [QS]; QS ++; // printf ("Now V is % d \ n", V ); for (INT I = 1; I <= T; I ++) {// if the target point is not labeled and there is residual traffic if (pre [I] =-2 & Dist [v] [I]-flow [v] [I]! = 0) {pre [I] = V; Alpha [I] = min (alpha [v], DIST [v] [I]-flow [v] [I]); Q [QE ++] = I ;}}// the increase path to the sink is not found. Exit if (pre [T] =-2) {break ;} // reverse update int Aval = Alpha [T]; for (INT I = T; Pre [I]! =-1; I = pre [I]) {flow [pre [I] [I] + = Aval; flow [I] [pre [I] =-flow [pre [I] [I] ;}// count traffic int ans = 0; for (INT I = 1; I <= N; I ++) {ans + = flow [I] [T];} printf ("% d \ n ", ans);} // dinicbool BFS () {Qs = Qe = 0; Q [QE ++] = s; memset (Level, 0, sizeof (level )); level [s] = 1; while (QS <QE) {int v = Q [QS ++]; If (V = T) break; For (INT I = s; I <= T; I ++) if (Cap [v] [I] &! Level [I]) {level [I] = level [v] + 1; Q [QE ++] = I ;}} return level [T];} int DFS (INT now, int alpha) {int sum = 0; If (now = T) return Alpha; For (INT I = s; I <= T; I ++) {If (level [I] = level [now] + 1 & Alpha & Cap [now] [I]) {int ret = DFS (I, min (alpha, Cap [now] [I]); CAP [now] [I]-= ret; CAP [I] [now] + = ret; alpha-= ret; sum + = ret;} return sum;} void dinic () {int ans = 0; while (BFS () ans + = DFS (S, int_max); printf ("% d \ n", ANS);} // judge the Euler loop of the mixed graph. // first, all edges are regarded as directed edges, determine whether the difference between the inbound and outbound degrees of all points is an even number. If an odd number appears, it is not an Euler loop. // Remove all the directed edges in the graph and create virtual Source and Sink points. If there is an inbound degree greater than the outbound degree in the remaining points, the edge of the sink point is established, the capacity is the difference between the inbound and outbound degrees/2. If an outbound degree is greater than the inbound level, the edge is built to the source point. The capacity is also half the difference between the inbound and outbound levels, when the maximum flow is performed, the traffic is equal to the number of edges to be swapped. // Using namespace STD; typedef long ll; const int maxn = 205; const int INF = int_max/3; struct edge {int U, V, CAP; edge (int u, int V, int cap): U (u), V (V), Cap (CAP) {}}; int n, m, incnt [maxn], outcnt [maxn]; int deg [maxn], S, T; vector <edge> edges; vector <int> E [maxn]; void Adde (int u, int V, int W) {int M = edges. size (); edges. push_back (edge (U, V, W); edges. push_back (edge (v, U, 0); e [u]. push_back (m ); E [v]. push_back (M ^ 1);} int level [maxn], Q [maxn * 2], QS, QE; bool BFS () {// create a hierarchical network memset (level, 0, sizeof (level); level [s] = 1; Qs = Qe = 0; Q [QE ++] = s; while (QS <QE) {int now = Q [QS ++], Nm = E [now]. size (); If (now = T) break; For (INT I = 0; I <Nm; I ++) {edge & Ne = edges [E [now] [I]; If (ne. cap & level [NE. v] = 0) {level [NE. v] = level [now] + 1; Q [QE ++] = ne. V ;}} return level [T];} int DFS (INT n Ow, int alpha) {If (now = T) return Alpha; int sum = 0, Nm = E [now]. size (); For (INT I = 0; I <Nm; I ++) {edge & Ne = edges [E [now] [I]; if (level [now] + 1 = level [NE. v] & ne. cap & alpha) {int ret = DFS (ne. v, min (alpha, ne. CAP); ne. cap-= ret; edges [E [now] [I] ^ 1]. cap + = ret; sum + = ret; alpha-= ret;} If (sum = 0) level [now] =-1; return sum;} void dinic () {While (BFS () DFS (S, INF);} bool solve () {S = 0; t = n + 1; // determines whether the deviation of inbound exit is an even number for (INT I = 1; I <= N; I ++) {deg [I] = incnt [I]-outcnt [I]; If (deg [I] & 1) return false ;} // create a capacity network for (INT I = 1; I <= N; I ++) {// If the inbound degree is smaller than the outbound degree, create an edge from the start point to this point, the capacity is deg/2 If (deg [I] <0) Adde (S, I,-deg [I]/2); // If the outbound degree is greater than the entry level, build the edge from the current point to the sink point. The capacity is also deg/2 If (deg [I]> 0) Adde (I, T, deg [I]/2 );} // calculate the maximum stream dinic (); // judge whether all edges starting from the source point are full streams int M = E [s]. size (); For (INT I = 0; I <m; I ++) {If (edges [E [S] [I]. Cap! = 0) return false;} return true;} int main () {int t; scanf ("% d", & T); While (t --) {scanf ("% d", & N, & M); edges. clear (); For (INT I = 0; I <= n + 1; I ++) E [I]. clear (); memset (incnt, 0, sizeof (incnt); memset (outcnt, 0, sizeof (outcnt); For (INT I = 1; I <= m; I ++) {int U, V, C; scanf ("% d", & U, & V, & C ); // process all undirected edges as directed edges first. incnt [v] ++; outcnt [u] ++; // If (C = 0) Adde (u, v, 1);} If (solve () puts ("possible"); e LSE puts ("impossible");} return 0;} // determines whether the minimum cut is unique. // The method for determining whether the maximum flow is the minimum cut is obtained first, then, we traverse all the points that can be reached from the source point and the sink point to see if all the points are covered. If all the points are covered, they are unique. Otherwise, they are not unique. Void solve () {// first perform the largest stream while (BFS () DFS (S, INF); // perform the BFS memset (VIS, 0, sizeof (VIS); Qs = Qe = 0; Q [QE ++] = s; vis [s] = true; while (QS <QE) {int now = Q [QS ++]; for (INT I = first [now]; ~ I; I = NXT [I]) {If (Cap [I] &! Vis [V [I]) {vis [V [I] = true; Q [QE ++] = V [I] ;}} Qs = Qe = 0; Q [QE ++] = T; vis [T] = true; while (QS <QE) {int now = Q [QS ++]; for (INT I = first [now]; ~ I; I = NXT [I]) {If (Cap [I ^ 1] &! Vis [V [I]) {vis [V [I] = true; Q [QE ++] = V [I] ;}} for (INT I = 1; I <= N; I ++) {If (! Vis [I]) {puts ("ambiguous"); Return ;}} puts ("unique ");} // a network stream with a capacity limit and a passive point and a collection point // create a virtual source point and a collection point. If the lower bound capacity is ignored, traffic imbalance occurs. Therefore, for each U, V, the excessive U traffic flows to the sink point, and the insufficient v traffic supplements the typedef long ll from the source point; const int maxn = 205; const int maxm = maxn * maxn; const int INF = int_max/3; int CAP [maxn] [maxn], flow [maxn] [maxn], low [maxm]; int Q [maxn], alpha [maxn], pre [maxn]; int UU [maxm], VV [maxm]; int n, m, S, T, QS, QE; void solve () {memset (flow, 0, sizeof (flo W); While (1) {Qs = Qe = 0; For (INT I = s; I <= T; I ++) Pre [I] =-2; pre [s] =-1; Alpha [s] = inf; Q [QE ++] = s; while (QS <QE) {int now = Q [QS ++]; for (INT I = s; I <= T; I ++) {If (Cap [now] [I]-flow [now] [I]! = 0 & Pre [I] =-2) {q [QE ++] = I; Pre [I] = now; alpha [I] = min (alpha [now], Cap [now] [I]-flow [now] [I]) ;}} if (pre [T] =-2) break; For (INT I = T; Pre [I]! =-1; I = pre [I]) {flow [pre [I] [I] + = Alpha [T]; flow [I] [pre [I]-= Alpha [T] ;}} bool OK = true; For (INT I = S + 1; I <= T; I ++) {If (Cap [s] [I]-flow [s] [I]) OK = false;} For (INT I = s; I <t; I ++) if (Cap [I] [T]-flow [I] [T]) OK = false; If (! OK) puts ("no"); else {puts ("yes"); For (INT I = 0; I <m; I ++) {printf ("% d \ n", flow [UU [I] [VV [I] + low [I]) ;}} int main () {scanf ("% d", & N, & M); s = 0; t = n + 1; memset (Cap, 0, sizeof (CAP )); for (INT I = 0; I <m; I ++) {int U, V, L, C; scanf ("% d ", & U, & V, & L, & C); low [I] = L; CAP [u] [v] + = c-l; cap [s] [v] + = L; CAP [u] [T] + = L; UU [I] = u; VV [I] = V ;} solve (); Return 0 ;}// the maximum number of matching int DFS (INT now) {for (I NT I = 1; I <= cnty; I ++) if (G [now] [I] &! Vis [I]) {vis [I] = true; If (! By [I] | DFS (by [I]) {BX [now] = I; by [I] = now; return 1 ;}} return 0 ;} int solve () {int ret = 0; memset (BX, 0, sizeof (BX); memset (by, 0, sizeof ()); for (INT I = 1; I <= cntx; I ++) if (! BX [I]) {memset (VIS, 0, sizeof (VIS); RET + = DFS (I);} return ret ;} // minimum point weight coverage-> Minimum Cut + split point // find the Maximum Independent Set, maximum independent point set = points-Maximum number of matched items note // minimum point coverage = maximum matching // minimum path overwrite = number of vertices-maximum matching