Route between two nodes in a directed graph

This technical problem deals with finding a route between two nodes in a directed graph. An example input is given, as well as the desired output.

Problem

Given a directed graph, design an algorithm to find out whether there is a route between two nodes.
Example input: 
A -> B
B -> C
C -> D
Example output: 
True

Solution

This solution is in C++. Our A.I. can create solutions in multiple languages.
by kayakane
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

class Node {
public:
	Node(int val) : val(val) {}
	int val;
	vector<Node*> children;
};

bool isRoute(Node* start, Node* end) {
	if (start == end) return true;
	queue<Node*> q;
	q.push(start);
	while (!q.empty()) {
		Node* curr = q.front();
		q.pop();
		for (Node* child : curr->children) {
			if (child == end) return true;
			q.push(child);
		}
	}
	return false;
}

int main() {
	Node* a = new Node(1);
	Node* b = new Node(2);
	Node* c = new Node(3);
	Node* d = new Node(4);
	a->children.push_back(b);
	b->children. push_back(c);
	c->children.push_back(d);
	cout << isRoute(a, d) << endl;
	cout << isRoute(a, c) << endl;
	cout << isRoute(a, a) << endl;
	cout << isRoute(a, b) << endl;
	cout << isRoute(d, a) << endl;
	return 0;
}

A.I. Evaluation of the Solution

The candidate's solution is correct and demonstrates a level of completeness. The candidate has correctly implemented a breadth-first search algorithm to find whether there is a route between two nodes in a directed graph.

Evaluated at: 2022-12-11 12:15:32