Bzoj 3436: Farm difference constraints for small k

Source: Internet
Author: User

3436: Little K's Farm time limit:10 Sec Memory limit:128 MB
submit:443 solved:220
[Submit] [Status] [Discuss] 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 situation with the memory of the small K match, output "Yes", otherwise output "No"

Sample Input33
312
1131
2232

Sample Output
Yes

Sample explanation

The number of three farms planted can be (2,2,1). puzzle: The love of the Q-god posture, this problem is a differential constraint
/************************************************************** problem:3436 user:1085422276 language:c++ result:wrong_answer****************************************************************/#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>#include<queue>#include<cmath>#include<map>using namespacestd; typedefLong Longll;#defineINF 100000#defineMAXN 10000+5inline 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;}//******************************************************************structss{intto,v;}; Vector<ss >G[MAXN];intflag=0, VIS[MAXN],DIS[MAXN];intn,m;voidDfsintx) {Vis[x]=1;  for(intI=0; I<g[x].size (); i++)    {        if(dis[g[x][i].to]>dis[x]+g[x][i].v) {            if(Vis[g[x][i].to]) {flag=1; return ; } Dis[g[x][i].to]=dis[x]+g[x][i].v;          DFS (G[X][I].TO); //vis[g[x][i].to]=1;}} Vis[x]=0;}intMain () {scanf ("%d%d",&n,&m);  for(intI=1; i<=n;i++)    {        intt=read (); intA,b,c; if(t==3) {scanf ("%d%d",&a,&b); G[a].push_back ((ss) {B,0}); }Else if(t==1) {scanf ("%d%d%d",&a,&b,&c); G[a].push_back ((ss) {B,-C}); }        Else{scanf ("%d%d%d",&a,&b,&c);        G[b].push_back ((ss) {a,c}); }} Flag=0; memset (DIS,127,sizeof(DIS));  for(intI=1; i<=n;i++) {Dis[i]=0;        DFS (i); if(flag) {cout<<"No"<<endl;return 0; }} cout<<"Yes"<<Endl; return 0;}
Code

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.