Memory search, force double can be too ... The data is simply.
1#include <cstdio>2#include <iostream>3#include <cstring>4#include <cmath>5#include <cstdlib>6 #defineLD double7 using namespacestd;8 Const intmaxn=1023, maxm=10023;9 ConstLD eps=1e-8;Ten structzs{intToo,pre;ld v;} e[maxm<<1];intTOT,LAST[MAXN]; One BOOLU[MAXN]; A ld VAL[MAXN]; - intI,j,k,n,m,ans; - BOOLFlag; the - intRA,FH;CharRx; -InlineintRead () { -Rx=getchar (), ra=0, fh=1; + while((rx<'0'|| Rx>'9') &&rx!='-') rx=GetChar (); - if(rx=='-') fh=-1, rx=GetChar (); + while(rx>='0'&&rx<='9') ra*=Ten, ra+=rx- -, Rx=getchar ();returnra*fh; A } atInlinevoidInsertintAintb,ld c) { -e[++tot].too=b,e[tot].v=c,e[tot].pre=last[a],last[a]=tot; - } - voidDfsintX,ld v) { - if(U[x])return; u[x]=1, val[x]=v; - for(intI=LAST[X];I&&FLAG;I=E[I].PRE)if(!u[e[i].too]) DFS (e[i].too,v*e[i].v); in Else if(Fabs (VAL[E[I].TOO]-V*E[I].V) >eps) flag=0; - } to intMain () {inta,b,c,d,tt=0; + for(intT=read (); T t--) {tt++,tot=0, Memset (Last,0, (n+1) <<2); -N=read (), m=read (); the for(i=1; i<=m;i++) *A=read (), B=read (), C=read (), d=read (), $Insert (A, B, (LD) d/c), insert (B,a, (LD) c/d);Panax Notoginsengflag=1, Memset (U,0, n+1); - for(i=1; i<=n&&flag;i++)if(!u[i]) DFS (i, (LD)1.0); theprintf"Case #%d:", TT); +Puts (flag?)"Yes":"No"); A } the return 0; + } -
View Code
[bzoj4602] [Sdoi2016] Gears