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