Hi, I hope somebody can help me here :-(... this program compiles well and after it crashes.

```
#include "TStack.h"
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
//FILE *f=fopen("input.txt","r");
//FILE *g=fopen("output.txt","w");
void main(){
int n;
scanf("%d", &n);
vector <vector<int> > g (n, vector<int> (n));
vector <int> deg (n);
for (int i=0; i<n; ++i)
for (int j=0; j<n; ++j)
deg[i]+=g[i][j];
int first=0;
while (!deg[first]) ++first;
int v1=-1, v2=-1;
bool bad=false;
for (int i=0; i<n; ++i)
if (deg[i] & 1)
if (v1==-1)
v1=i;
else if (v2==-1)
v2=i;
else bad=true;
if (v1!=-1){
++g[v1][v2];
++g[v2][v1];
}
TStack st;
st.push (first);
vector<int> res;
while (!st.empty()){
int v=st.pop();
int i;
for (i=0; i<n; ++i)
if (g[v][i]) break;
if (i==n){
res.push_back(v);
st.pop();
}
else{
--g[v][i];
--g[i][v];
st.push (i);
}
}
if (v1!=-1)
for (size_t i=0; i+1<res.size(); ++i)
if (res[i]==v1 && res[i+1]==v2 || res[i]==v2 && res[i+1] ==v1){
vector<int> res2;
for (size_t j=i+1; j<res.size(); ++j)
res2.push_back (res[j]);
for (size_t j=1; j<=1; ++j)
res2.push_back (res[j]);
res=res2;
break;
}
for (int i=0; i<n; ++i)
for (int j=0; j<n; ++j)
if (g[i][j])
bad=true;
if (bad) puts ("-1");
}
```

I went through the code several times but I don't find any errors... somebody has a hint?

Thanks all!