"minute detail" ...
not true
has only "
minute" difference from
true
, yet the result could not be more different.
Of cource small edits can cause huge changes, if they change the logic.
1 2 3 4 5 6 7 8 9 10 11 12
|
int n, g, s, cow;
fin>>n>>g;
for (int i=0; i<g; i++) {
fin>>s;
for (int j=0; j<s; j++) {
fin>>cow;
gr.insert(--cow);
belong[cow].push_back(i);
}
groups.push_back(gr);
gr.clear();
}
|
int n, g, s, cow;
fin>>n>>g;
for (int i=1; i<=g; i++) {
fin>>s;
for (int j=0; j<s; j++) {
fin>>cow;
gr.insert(cow);
belong[cow].push_back(i);
}
groups.push_back(gr);
gr.clear();
} |
You have made three changes.
1. You have changed what values does the 'i' get and therefore what values are stored in the vectors of 'belong'.
2. You change what you store in 'gr' and where you store in 'belong'. I won't even try to check whether and how 'belong' and 'gr' are related, but my first instinct says: "
that is a mess".
If you want to change the 'i' and 'i' only, then write:
1 2 3 4 5 6 7 8 9 10 11 12
|
int n, g, s, cow;
fin>>n>>g;
for (int i=1; i<=g; i++) {
fin>>s;
for (int j=0; j<s; j++) {
fin>>cow;
gr.insert(--cow);
belong[cow].push_back(i-1);
}
groups.push_back(gr);
gr.clear();
}
|
Given
vector<int> belong [1000001];
the
fin >> cow; belong[cow].push_back(value);
is scary in both versions, unless you can completely, blindly, and entirely trust that all reads from input file succeed and produce valid array indices.