terminate called after throwing an instance of 'std::bad_alloc'
Problem.
terminate called after throwing an instance of 'std::bad_alloc'
what(): St9bad_alloc
Aborted
|
My Program.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
int main()
{
int vertices;
int edges;
int a,b;
while(cin >> vertices)
{
cin >> edges;
vector< vector<int> > adj_list(vertices);
for(int i=0;i<edges;i++)
{
cin >> a>> b;
adj_list[a].push_back(b);
}
for(int i=0;i<adj_list.size();i++)
{
for(int j=0;j<adj_list[i].size();j++)
cout << adj_list[i][j] << " ";
cout << endl;
}
}
return 0;
}
|
Sample Input
3
3
0 1
1 2
2 0
9
8
0 1
0 2
0 3
0 4
0 5
0 6
0 7
0
|
Program Output.
1
2
0
1 2 3 4 5 6 7 8
terminate called after throwing an instance of 'std::bad_alloc'
what(): St9bad_alloc
Aborted
|
You're missing the 8th edge on your input data.
Topic archived. No new replies allowed.