Table queries, a DFS is available. First of all, the problem is a judgment question. And because this question is a bit like a check-up constraint, it should be possible to prove that the number of schemes should be infinite if they exist (with Konjac konjac feeling). And you can specify the size of the value of a point, and determine whether the other values are satisfied. The implementation is a bit like Two-sat. That's probably it. Come on! If you have time, come back and think about it.
Think about it. If the output of a scheme is required, also run the upper and lower limit of the network flow, in particular, the s set point I toward the T-set point J, the upper and lower bound is V (i,j) edge.
1#include <cstdio>2#include <iostream>3 #defineRep (i,j,k) for (register int i = j; I <= K; i++)4 #defineEZ (I,J) for (edge*i = head[j]; i; i=i->next)5 #defineMAXN 10056 using namespacestd;7 8InlineintRead () {9 ints =0, t =1;Charc =GetChar ();Ten while(!isdigit (c)) {if(c = ='-') T =-1; c =GetChar ();} One while(IsDigit (c)) s = S *Ten+ C- -, C =GetChar (); A returnS *T; - } - the structedge{intTo, V; Edge*next; } e[maxn<<1], *pt = e, *head[maxn<<1]; -InlinevoidAddintXintYintV) {pt->to = y, Pt->next = head[x], pt->v = V, head[x] = pt++; pt->to = x, pt->v = V, pt->next = head[y ], head[y] = pt++; } - intd[maxn<<1];BOOLFlag, vis[maxn<<1]; - #defineTo I->to +InlinevoidDfsintXintNV) { -D[X] = NV; VIS[X] =1; + EZ (i,x) { A if(Vis[to]) {if(D[to]! = I->V-NV) {flag =0; Break; }Continue; } at ElseDFS (to,i->v-nv); - } - } - - intMain () { - intN, M, K, X, Y, V, t =read (); in while(t-- ) { -n = Read (), M = Read (), k =read (); toRep (I,1, n+m) vis[i] = d[i] =0, head[i] =0; PT =e; +Rep (I,1, k) x = Read (), y = read () + N, v =read (), add (x,y,v); -Flag =1; theRep (I,1, n+m) { * if(!vis[i]) DFS (i,0); $ if(!flag) Break;Panax Notoginseng } - if(flag) puts ("Yes");ElsePuts"No"); the } + return 0; A}
4500: Matrix DFS