Bzoj 3436: Farm difference constraints for small k

Source: Internet
Author: User

3436: Little K's Farm

Time Limit:1 Sec

Memory limit:256 MB

Topic Connection http://www.lydsy.com/JudgeOnline/problem.php?id=3436
Description

Background

Small k is a special love to play MC children's paper ...

Describe

Small k in the MC built many farms, a total of N, so that he has forgotten the specific number of crops planted on each farm, he only remember some vague information (a total of M), described in the following three forms: farm A more than farm b at least planted C units of crops, Farm A has grown more than farm B with a C-unit crop, and farm A has as many crops as farm B. However, because the memory of little K is somewhat biased, he wants to know if there is a situation where the number of crops planted on the farm matches all the information in his memory. Input format

Input

The first line consists of two integers n and m, each representing the number of farm numbers and information in small K memory

Next M-Line:

If the first number of each row is 1, then there are three integer a,b,c, which indicates that farm A has at least more than Farm B plant a C-unit crop if the first number per row is 2, followed by three integer a,b,c, which indicates that farm A has more than farm B plants with a C unit.

If the first number in each row is 3, then there are two integers, a, a, which indicates that farm a grows as many output formats as B

Output if there is a condition that matches the memory of the small K, outputs "Yes", otherwise output "No" Sample Input

33
312
1131
2232

Sample outputyeshint1<=n,m,a,b,c<=10000

Test instructions

Exercises

Differential constraints

It would be nice to have a negative ring when looking.

Code:

//Qscqesze#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<bitset>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<fstream>#include<map>#include<stack>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineMAXN 11000#defineMoD 10007#defineEPS 1e-9intNum;//const int INF=0X7FFFFFFF; //§ß§é§à§é¨f§³Const intinf=0x3f3f3f3f; inline ll read () {ll x=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}//**************************************************************************************structnode{intx, y;}; Vector<node>E[MAXN];intINQ[MAXN],DIS[MAXN];intflag=0;voidSolveintx) {    if(flag)return; INQ[X]=1;  for(intI=0; I<e[x].size (); i++) {node v=E[x][i]; if(dis[v.x]>dis[x]+v.y) {dis[v.x]=dis[x]+v.y; if(inq[v.x]) {flag=1; return; }            if(!inq[v.x]) {dis[v.x]=dis[x]+v.y;            Solve (v.x); }}} Inq[x]=0;}intMain () {intN=read (), m=read ();  for(intI=0; i<=n;i++) Dis[i]=inf;  for(intI=1; i<=m;i++)    {        intA=read (), B=read (), c=read (); if(a==1)        {            intE=read (); E[b].push_back (node) {C,-e}); }        if(a==2)        {            intE=read ();        E[c].push_back (node) {b,e}); }        if(a==3) {e[b].push_back (node) {C,0}); }    }     for(intI=1; i<=n;i++) Dis[i]=0, solve (i); if(flag) printf ("no\n"); Elseprintf"yes\n");}

Bzoj 3436: Farm difference constraints for small k

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.