|
|
back to boardwhy it says compiler error Posted by bayram 25 Sep 2012 13:41 # include <stdio.h> # include <iostream> # include <algorithm> # include <math.h> # define max1 50009 # define max2 75009 using namespace std; int path[max1][2]; int n,m,a,b,c,path1,path2; int ans[max2]; int min1(int x,int y) { if(x<y) return x;
return y;
} int main() { cin>>n;
for(int h=0; h<n-1; h++) { cin>>a>>b>>c;
a++; b++;
if(max(a,b)%2==0) path[min1(a,b)][0]=c;
else path[min1(a,b)][1]=c; }
cin>>m;
for(int h=0; h<m; h++) { cin>>a>>b;
a++; b++;
path1=0; path2=0;
while(b!=a) { int s1=1,s2=1; int d1=s1<<((int)log2((double)b)); int d2=s2<<((int)log2((double)a));
if(d1<=a) { if(a%2==0) path1+=path[a/2][0];
else path1+=path[a/2][1];
a/=2; }
if(d2<=b) { if(b%2==0) path2+=path[b/2][0];
else path2+=path[b/2][1];
b/=2; }
ans[h]=path1+path2;
}
}
for(int h=0; h<m; h++) cout<<ans[h];
} |
|
|