Process exited with value 3221225477

Hello, I'm kinda new to programming. I was asked to write a program about network flow. but when i try to run my code, it returns with an unexpected error and crashes. return value is given in the title. Do you know anyting about the issue?
Oh by the way, when i remove the line when i call the method below, it returns 0 as normal. Though the output is not what i want. I could really use some help.
Thanks in advance!
1
2
3
4
5
6
7
8
vector <bool> visited; // vector to determine each node is visited or not.
visited.resize(graphSize);

void makeUnvisited(){
	for(int j=0; j<visited.size(); j++){
		visited[j]=false;
	}
}


I can post my whole code if you want. Thanks!
Yes, please post more of the code. The part you've shown looks OK.

You may also want to use a debugger to find out where it is crashing and why.
visited.resize(graphSize);

I think this is your problem. This line should be inside of a function, so try moving it to one of the earlier lines in your main function.
That error probably means you are going out of bounds on your vector somewhere but it is hard to tell. I recommend you post more of your code.

I agree that resizing in global scope is a bad idea though.
Last edited on
If the TC really had that line in global scope, the program wouldn't compile. I suspect that this is just trying to show the parts TC thinks is relevant.
^ That.
Maybe graphSize has a invalid size tho.

IRRELEVANT TO THE OP:
You cannot execute function calls on the global scope, unless you store the return value somewhere.

1
2
3
4
5
6
// Example: You cannot do this:
strcpy(a,b);
// But you can do this:
char* p_random_name = strcpy(a,b);
// Or
char* p_random_name_2(strcpy(a,b));
Last edited on
> I suspect that this is just trying to show the parts TC thinks is relevant.
Quite a bad decision http://www.eelis.net/iso-c++/testcase.xhtml (point 6)
sorry for the inconvenience, i'm not resizing in global scope. it's in a function. I also tried with iterator instead of for loop, result was the same. Anyway, here's my full code:
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include <iostream>
#include <vector>
#include <fstream>
#include <stack>

using namespace std;
int studentNum;
int courseNum;
int graphSize;
int tempN, tempC;
stack <int> nodeStack;
vector <int> courseQuotas;
vector <bool> visited(2);

class Student{
public:
	int name;
	int courseCount;
	vector <int> givenCourses;
	vector <int> wantedCourses;
public:	
	Student(){
		name=0;
	}
	Student(int x, int y){
		courseCount=y;
		name=x;
	}
	void addCourses(int x){
		wantedCourses.push_back(x);
	}
};
class Edge{
public:	
	int s,t,weight, marked;
	Edge(){
		s=0;
		t=0;
		weight=1;
		marked=-1;
	}
	Edge(int x, int y){
		s=x;
		t=y;
		weight=1;
		marked=-1;
	}
	Edge(int x, int y, int z){
		s=x;
		t=y;
		weight=z;
		marked=-1;
	}
	void changeMark(){
		marked=(-1)*marked;
	}
	Edge reverse(){
		return Edge(t, s, weight);		
	}
	Edge& operator=(const Edge &v){
		if(this!=&v){
			s=v.s;
			t=v.t;
			weight=v.weight;
			marked=v.marked;
		}
		return *this;
	}
	//Destructor
	~Edge(){

	}
};


vector <Student> students;
void readFile(){
	ifstream input;
	input.open("project4.gir");
	input >> studentNum;
	input >> courseNum;
	for(int i=0; i<studentNum; i++){
		input >> tempN;
		input >> tempC;
		students.push_back(Student(i, tempC));
		for(int j=0; j<tempN; j++){
			int course;
			input >> course;
			students.at(i).addCourses(course);
		}
	}
	for(int i=0; i<courseNum; i++){
		int quota;
		input >> quota;
		courseQuotas.push_back(quota);
	}
	graphSize=2+studentNum+courseNum;
	input.close();
}
vector < vector <Edge> > graph;
void createGraph(){
	graph.resize(graphSize);
	visited.resize(graphSize);
	for(int i=0; i<graphSize; i++){
		visited.at(i)=false;
	}
	for(int i=0; i<studentNum; i++){
		graph.at(0).push_back(Edge(0, i+1, 1));
		for(int j=0; j<students.at(i).wantedCourses.size(); j++){
			graph.at(i+1).push_back(Edge(i+1, studentNum+students.at(i).wantedCourses.at(j) , 1));
		}
	}
	for(int i=0; i<courseNum; i++){
		if(courseQuotas.at(i)!=0){
			graph.at(i+1+studentNum).push_back(Edge(i+1+studentNum, 1+studentNum+courseNum , courseQuotas.at(i)));
		}
	}
}
void dfs(int vertex){
	nodeStack.push(vertex);
	visited.at(vertex)=true;
	if(vertex==graphSize) return;
		while(!nodeStack.empty()){
			int node = nodeStack.top();
			nodeStack.pop();	
			if(visited.at(graphSize-1)) break;
			for(int i=0; i<graph.at(node).size(); i++){
				if(!visited.at(graph.at(node).at(i).t)){
					nodeStack.push(graph.at(node).at(i).t);
					visited.at(graph.at(node).at(i).t)=true;
					cout << "Going from " << graph.at(node).at(i).s << " to " << graph.at(node).at(i).t << endl;				
					if(i<=studentNum){
						Edge temp = graph.at(node).at(i).reverse();
						temp.changeMark();
						graph.at(graph.at(node).at(i).t).push_back(temp);
						graph.at(node).erase(graph.at(node).begin()+i-1);
					}
					break;
				}
			}
		}
		visited.at(graphSize-1)=false;
		cout << "----------------------------" << endl;
}
void makeUnvisited(){
	vector<bool>::iterator it;
	for(it=visited.begin(); it<visited.end(); it++){
		visited.at(*it)=false;
	}
}
int main(){
	readFile();
	createGraph();
	/*
	for(int i=0; i<graph.size()-1; i++){
		cout << "The edges from node " << i << ": " << endl;;
		for(int j=0; j<graph.at(i).size(); j++){
			cout << "	Source node: "<< graph.at(i).at(j).s << endl; 
			cout << "	Target node: "<< graph.at(i).at(j).t << endl; 
			cout << "	Weight of the edge: "<< graph.at(i).at(j).weight << endl; 
			cout << "		---" << endl;
		}
		cout << "--------------------------" << endl;
	}
	*/
	for(int i=0; i<studentNum; i++){
		dfs(0);
		makeUnvisited();
	}	
return 0;
}
does anyone know what this return value is about? i could really use some help :)
http://stackoverflow.com/questions/10306272/apache-crashing-parent-child-process-exited-with-status-3221225477-restarti

it says you are trying to access memory you shouldn't :
some sort of :
1
2
3
int arr[ 10 ];

arr[ 11 ] = 100; // segmentation fault ! 
yes, I just realized that in line 136 there's a useless "-1". now i change it to

graph.at(node).erase(graph.at(node).begin()+i);

instead of

graph.at(node).erase(graph.at(node).begin()+i-1);

it seems like i've fixed the problem. Still don't understand why it returned 0 when i deleted makeUnvisited method below.

1
2
3
4
5
6
 void makeUnvisited(){
	vector<bool>::iterator it;
	for(it=visited.begin(); it<visited.end(); it++){
		visited.at(*it)=false;
	}
}


Again, thanks so much!
Last edited on
+1 for using a debugger to find out where it's crashing and what the state of your memory is at that point.

One thing to bear in mind is that a vector of bool doesn't behave exactly as a vector of any other type does, but uses a specialised implementation:

http://www.cplusplus.com/reference/vector/vector-bool/

I'm no expert in exactly what those differences are, but it may be that you're doing something with that vector that would be appropriate for a normal vector, but not for vector<bool>.

EDIT: Ninja'd by shadow fiend, while I was interrupted in writing my reply.
Last edited on
so do you think it would be better for me to use a vector of int and store only 1's and 0's?
Well, if you've found the problem, and it was nothing to do with using a vector of bool, I don't see any reason to change. The reason for having a specialisation for bool is to have increased memory efficiency. Unless you come across other problems relating to the specialisation, I'd say it's best to keep it as it is.
1
2
3
4
5
6
 void makeUnvisited(){
	vector<bool>::iterator it;
	for(it=visited.begin(); it<visited.end(); it++){
		visited.at(*it)=false;
	}
}


it should be :
1
2
3
4
5
6
void makeUnvisited( )
{
    // replace auto w/ vector<bool>::iterator if you have not enabled -std=c++11
    for( auto it = visited.begin(); it != visited.end(); ++it )
        *it = false;
}
Topic archived. No new replies allowed.