Bzoj 2330: [SCOI2011] Candy

Source: Internet
Author: User

1#include <cstdio>2#include <iostream>3 using namespacestd;4 intn,m,cnt,head[100006],next[400006],u[400006],v[400006],h,t,a[100006];5 intci[100006],f[100006];6 Long Longd[100006];7 voidJiaintA1,intA2,intA3)8 {9cnt++;Tennext[cnt]=HEAD[A1]; Onehead[a1]=CNT; Au[cnt]=A2; -v[cnt]=A3; - } the intMain () - { -scanf"%d%d",&n,&m); -      for(intI=0; i<m;i++) +       { -         inta1,a2,a3; +scanf"%d%d%d",&a1,&a2,&A3); A         if(a1==1) at           { -Jia (A2,a3,0); -Jia (A3,A2,0); -             } -         if(a1==2) -{if(A2==A3) {printf ("-1");return 0;} inJia (A2,a3,1);} -         if(a1==3) toJia (A3,A2,0); +         if(a1==4) -{if(A2==A3) {printf ("-1");return 0;} theJia (A3,A2,1);} *         if(a1==5) $Jia (A2,a3,0);Panax Notoginseng       } -      for(inti=n;i;i--) theJia0I1); +a[1]=0; Aci[0]++; thet=1; +f[0]=1; -      for(; h!=t;) $       { $h++; -         if(h>100004) -H=1; thef[a[h]]=0; -          for(intI=head[a[h]];i;i=Next[i])Wuyi           if(d[u[i]]<d[a[h]]+V[i]) the             { -d[u[i]]=d[a[h]]+V[i]; Wuci[u[i]]++; -                 if(ci[u[i]]==n+1) About                   { $printf"-1\n"); -                     return 0; -                     } -                 if(!F[u[i]]) A                   { +t++; the                     if(t>100004) -t=1; $a[t]=U[i]; thef[u[i]]=1; the                   } the               } the       } -     Long Longans=0; in      for(intI=1; i<=n;i++) theans+=D[i]; theprintf"%lld", ans); About     return 0; the}

Differential constraint system, based on the conditions to build the shortest path.

Bzoj 2330: [SCOI2011] Candy

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: 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.