|
|
вернуться в форумTLE test1??? Why the hell this c program gets TLE on test 1? It works perfectly on sample. #include <stdio.h> int main() { int ar[40000],n,i,a,b,l,ta,tb; char o[40000]; //freopen("in","r",stdin); scanf("%d",&n); for(i=0;i<n;i++) ar[i]=0; for(i=0;i<n;i++) { scanf("%d%d",&a,&b); a--; ar[a]=b; } scanf("%d",&l); for(i=0;i<l;i++) { scanf("%d%d",&a,&b); a--; b--; ta=a; tb=b; while(ta!=-1&&ta!=b&&ta!=0) ta=ar[ta]-1; if(ta==b) { o[i]=2; //printf("2\n"); continue; } while(tb!=-1&&tb!=a&&ta!=0) tb=ar[tb]-1; if(tb==a) { o[i]=1; //printf("1\n"); continue; } o[i]=0; //printf("0\n"); } for(i=0;i<l;i++) printf("\n%d",o[i]); return 0; } |
|
|