|
|
вернуться в форумRuntime Error (access violation) #17 Why Runtime Error? #include <cstdio> #include <vector> #include <algorithm> using namespace std; int main() { unsigned short n, m; scanf("%hu", &n); vector <unsigned long long> bytes(n); vector <vector<unsigned short> > red(n); for(unsigned short i=0;i<n;i++) scanf("%llu", &bytes[i]); for(unsigned short i=1;i<n;i++) { unsigned short x, y; scanf("%hu %hu", &x, &y); red[x-1].push_back(y); red[y-1].push_back(x); } if(n>1) { for(unsigned short i=0;i<red.size();i++) sort(red[i].begin(), red[i].end()); for(unsigned short i=0;i<red.size();i++) { for(unsigned short j=0;j<red[i].size()-1;j++) { if(red[i][j]==red[i][j+1]) { for(unsigned short pos=j+1;pos<red[i].size()-1;pos++) red[i][pos] = red[i][pos+1]; red[i].pop_back(); } } } } scanf("%hu", &m); for(int i=0;i<m;i++) { unsigned short v, t; scanf("%hu %hu", &t, &v); if(t==1) { for(unsigned j=0;j<red[v-1].size();j++) bytes[red[v-1][j]-1] += bytes[v-1]; } if(t==2) printf("%llu\n", bytes[v-1]%1000000007); } } |
|
|