Title Description
Transmission Door
Exercises
Just beginning to feel that only a few intervals and a few other intervals to spell the same interval can be sentenced to false, and then Xjblg wrote a No to the beat of the code and then handed in a = = Visible data is weak.
The positive solution on the net is and check the set, yy for quite a long time.
Read-in Interval (l,r,w), if L and R are not in a set, merge them, otherwise determine whether Dis_r-dis_x equals W (where dis_i represents I to the distance of its ancestors)
Code
Xjblg
#include <algorithm>#include <iostream>#include <cstring>#include <cstdio>using namespace STD;Const intmax_n= the;Const intmax_m=1005;intT,n,m;BOOLFlag,vis[max_n][max_n];intF[max_n][max_n];structhp{intX,y,w;} EDGE[MAX_M];inline voidClear () {memset(Vis,0,sizeof(VIS));memset(F,0,sizeof(f));inline intCMP (HP a,hp b) {returna.x<b.x| | (A.X==B.X&&A.Y<B.Y);}intMain () {scanf("%d", &t); while(t--) {Clear ();scanf("%d%d", &n,&m); for(intI=1; i<=m;++i)scanf("%d%d%d", &EDGE[I].X,&EDGE[I].Y,&EDGE[I].W); Sort (edge+1, edge+m+1, CMP); flag=true; for(intI=1; i<=m;++i) {if(!vis[edge[i].x][edge[i].y]) {vis[edge[i].x][edge[i].y]=true; F[EDGE[I].X][EDGE[I].Y]=EDGE[I].W; }Else if(F[EDGE[I].X][EDGE[I].Y]!=EDGE[I].W) {flag=false; Break; } for(intj=edge[i].x-1; j>=1;--j) {if(vis[j][edge[i].x-1]) {if(!vis[j][edge[i].y]) {vis[j][edge[i].y]=true; f[j][edge[i].y]=f[j][edge[i].x-1]+F[EDGE[I].X][EDGE[I].Y]; }Else if(f[j][edge[i].y]!=f[j][edge[i].x-1]+F[EDGE[I].X][EDGE[I].Y]) {flag=false; Break; } } }if(!flag) Break; }if(flag)printf("true\n");Else printf("false\n"); }}
and check the set + prefix and
#include <iostream>#include <cstring>#include <cstdio>using namespace STD;Const intmax_n= the;intT,N,M,L,R,W,FL,FR;BOOLFlagintF[max_n],dis[max_n];inline intFindintx) {if(X!=f[x]) {intT=find (F[x]); DIS[X]+=DIS[F[X]]; f[x]=t; }returnF[X];}intMain () {scanf("%d", &t); while(t--) {scanf("%d%d", &n,&m); for(intI=0; i<=n;++i) f[i]=i,dis[i]=0; flag=true; for(intI=1; i<=m;++i) {scanf("%d%d%d", &l,&r,&w); l--; Fl=find (l); Fr=find (R);if(FL!=FR) {dis[fr]=dis[l]-dis[r]+w; F[FR]=FL; }Else if(dis[r]-dis[l]!=w) flag=false; }if(flag)printf("true\n");Else printf("false\n"); }}
[BZOJ1202] [HNOI2005] cunning businessman (and check set + prefix and)