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.


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: 


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 {
	Node(int val) : val(val) {}
	int val;
	vector<Node*> children;

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

int main() {
	Node* a = new Node(1);
	Node* b = new Node(2);
	Node* c = new Node(3);
	Node* d = new Node(4);
	b->children. push_back(c);
	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