Finding the longest route in a graph

Hello, here's a snippet of the code to give you an idea of what i'm doing here. The function is suppoed to:
*return the starting node that gives a longest DFS run before running out of budget
*if there are multiple nodes with the same DFS run length, return the smallest node

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
int Graph::DFS(int startNode) {
	for (int i = 0; i < numNodes; i++) {
		visited[i] = false;
	}
	nodesVisited = 0;
	tempbud = budget;
	return dfsHelper(startNode);
}

int Graph::dfsHelper(int startNode) {
	visited[startNode] = true;
	nodesVisited++;
	tempbud += getValue(startNode);
	for (int i = 0; i < numNodes; i++) {
		if (matrix[startNode][i] && !visited[i] && tempbud > 0) { dfsHelper(i); }
	}
	return nodesVisited;
}

int bestStartvertex(){}



Last edited on
¿so? ¿what's the problem?
Topic archived. No new replies allowed.