4500: Matrix DFS

Source: Internet
Author: User

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-&GT;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.