This is where the bug would appear during execution:
C[check].S = vector<int>(S1);
end C is a global struct array and is defined as:
typedef struct C_type{
double e;
vector <int> S;
}Cache;
Cache *C;
Now this problem is sometimes it get segmentation fault error, so any hint to fix that? (S1 is not empty and S[check].S is always empty).