{"id":26222769,"url":"https://github.com/mmushfiq/trainsandtowns","last_synced_at":"2026-05-25T10:31:48.975Z","repository":{"id":83787370,"uuid":"131203301","full_name":"mmushfiq/TrainsAndTowns","owner":"mmushfiq","description":"Programming problem regarding Graph","archived":false,"fork":false,"pushed_at":"2018-04-29T11:35:47.000Z","size":18,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-12-26T21:59:20.680Z","etag":null,"topics":["dfs-algorithm","graph","graph-algorithms","java","shortest-paths"],"latest_commit_sha":null,"homepage":"http://www.mycertnotes.com/en/trains-and-towns-programming-problem-regarding-graph/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mmushfiq.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-04-26T19:47:37.000Z","updated_at":"2018-04-29T11:36:48.000Z","dependencies_parsed_at":null,"dependency_job_id":"9365d695-43f6-4d74-b228-5ee65823e6f4","html_url":"https://github.com/mmushfiq/TrainsAndTowns","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mmushfiq/TrainsAndTowns","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmushfiq%2FTrainsAndTowns","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmushfiq%2FTrainsAndTowns/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmushfiq%2FTrainsAndTowns/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmushfiq%2FTrainsAndTowns/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mmushfiq","download_url":"https://codeload.github.com/mmushfiq/TrainsAndTowns/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmushfiq%2FTrainsAndTowns/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33471517,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-25T06:32:55.349Z","status":"ssl_error","status_checked_at":"2026-05-25T06:32:35.322Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dfs-algorithm","graph","graph-algorithms","java","shortest-paths"],"created_at":"2025-03-12T17:19:40.704Z","updated_at":"2026-05-25T10:31:48.965Z","avatar_url":"https://github.com/mmushfiq.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TrainsAndTowns\nCoding task regarding Graph\n\n *  Compilation:  `javac Main.java`\n *  Execution:    `java Main \"AB5, BC4, CD8, DC8, DE6, AD5, CE2, EB3, AE7\"`\n\n### Description:\nThe local commuter railroad services a number of towns in Azerbaijan. Because of monetary concerns, all of the tracks are 'one-way.' That is, a route from `A` to `B` does not imply the existence of a route from `B` to `A`.\nIn fact, even if both of these routes do happen to exist, they are distinct and are not necessarily _the same distance_!\n\nThe purpose of this problem is to help the railroad provide its customers with information about the routes.\nIn particular, you will compute the\n\u003cul\u003e\n \t\u003cli\u003edistance along a certain route,\u003c/li\u003e\n \t\u003cli\u003ethe number of different routes between two towns,\u003c/li\u003e\n \t\u003cli\u003eand the shortest route between two towns.\u003c/li\u003e\n\u003c/ul\u003e\n\u0026nbsp;\n\n\u003cstrong\u003eInput:\u003c/strong\u003e A directed graph where a node represents a town and an edge represents a route between two towns. The weighting of the edge represents the distance between the two towns. A given route will never appear more than once, and for a given route, the starting and ending town will not be the same town.\n\n\u003cstrong\u003eOutput:\u003c/strong\u003e For test input 1 through 5, if no such route exists, output \u003ccode\u003e'NO SUCH ROUTE'\u003c/code\u003e. Otherwise, follow the route as given; do not make any extra stops! For example, the first problem means to start at city \u003ccode\u003eA\u003c/code\u003e, then travel directly to city \u003ccode\u003eB\u003c/code\u003e (a distance of 5), then directly to city \u003ccode\u003eC\u003c/code\u003e (a distance of 4).\n\n\u003cp\u003e\u003cstrong\u003e1.\u003c/strong\u003e The distance of the route \u003ccode\u003eA-B-C\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003e2.\u003c/strong\u003e The distance of the route \u003ccode\u003eA-D\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003e3.\u003c/strong\u003e The distance of the route \u003ccode\u003eA-D-C\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003e4.\u003c/strong\u003e The distance of the route \u003ccode\u003eA-E-B-C-D\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003e5\u003c/strong\u003e. The distance of the route \u003ccode\u003eA-E-D\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003e6.\u003c/strong\u003e The number of trips starting at \u003ccode\u003eC\u003c/code\u003e and ending at \u003ccode\u003eC\u003c/code\u003e with a maximum of \u003ccode\u003e3\u003c/code\u003e stops. In the sample data below, there are two such trips: \u003ccode\u003eC-D-C\u003c/code\u003e (2 stops) and \u003ccode\u003eC-E-B-C\u003c/code\u003e (3 stops).\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003e7.\u003c/strong\u003e The number of trips starting at \u003ccode\u003eA\u003c/code\u003e and ending at\u003ccode\u003e C\u003c/code\u003e with exactly \u003ccode\u003e4\u003c/code\u003e stops. In the sample data below, there are three such trips: \u003ccode\u003eA\u003c/code\u003e to \u003ccode\u003eC\u003c/code\u003e (via \u003ccode\u003eB\u003c/code\u003e, \u003ccode\u003eC\u003c/code\u003e, \u003ccode\u003eD\u003c/code\u003e); \u003ccode\u003eA\u003c/code\u003e to \u003ccode\u003eC\u003c/code\u003e (via \u003ccode\u003eD\u003c/code\u003e, \u003ccode\u003eC\u003c/code\u003e, \u003ccode\u003eD\u003c/code\u003e);\nand \u003ccode\u003eA\u003c/code\u003e to \u003ccode\u003eC\u003c/code\u003e (via \u003ccode\u003eD\u003c/code\u003e, \u003ccode\u003eE\u003c/code\u003e, \u003ccode\u003eB\u003c/code\u003e).\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003e8.\u003c/strong\u003e The length of the shortest route (in terms of distance to travel) from \u003ccode\u003eA\u003c/code\u003e to \u003ccode\u003eC\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003e9.\u003c/strong\u003e The length of the shortest route (in terms of distance to travel) from \u003ccode\u003eB\u003c/code\u003e to \u003ccode\u003eB\u003c/code\u003e.\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003e10.\u003c/strong\u003eThe number of different routes from \u003ccode\u003eC\u003c/code\u003e to \u003ccode\u003eC\u003c/code\u003e with a distance of less than \u003ccode\u003e30\u003c/code\u003e. In the sample data, the trips are:\n\u003ccode\u003eCDC\u003c/code\u003e,\u003ccode\u003e CEBC\u003c/code\u003e,\u003ccode\u003e CEBCDC\u003c/code\u003e,\u003ccode\u003e CDCEBC\u003c/code\u003e,\u003ccode\u003e CDEBC\u003c/code\u003e,\u003ccode\u003e CEBCEBC\u003c/code\u003e,\u003ccode\u003e CEBCEBCEBC\u003c/code\u003e.\u003c/p\u003e\n\n\u0026nbsp;\n\n\u003cstrong\u003eTest Input:\u003c/strong\u003e\nFor the test input, the towns are named using the first few letters of the alphabet from \u003ccode\u003eA\u003c/code\u003e to \u003ccode\u003eE\u003c/code\u003e. A route between two towns (\u003ccode\u003eA\u003c/code\u003e to \u003ccode\u003eB\u003c/code\u003e) with a distance of \u003ccode\u003e5\u003c/code\u003e is represented as \u003ccode\u003eAB5\u003c/code\u003e.\n\u003cp\u003e\u003ccode\u003eGraph: AB5, BC4, CD8, DC8, DE6, AD5, CE2, EB3, AE7\u003c/code\u003e\u003c/p\u003e\n\n\u003cstrong\u003eExpected Output:\u003c/strong\u003e\n* Output #1:    \u003ccode\u003e9\u003c/code\u003e\n* Output #2:    \u003ccode\u003e5\u003c/code\u003e\n* Output #3:    \u003ccode\u003e13\u003c/code\u003e\n* Output #4:    \u003ccode\u003e22\u003c/code\u003e\n* Output #5:    \u003ccode\u003eNO SUCH ROUTE\u003c/code\u003e\n* Output #6:    \u003ccode\u003e2\u003c/code\u003e\n* Output #7:    \u003ccode\u003e3\u003c/code\u003e\n* Output #8:    \u003ccode\u003e9\u003c/code\u003e\n* Output #9:    \u003ccode\u003e9\u003c/code\u003e\n* Output #10:  \u003ccode\u003e7\u003c/code\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmmushfiq%2Ftrainsandtowns","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmmushfiq%2Ftrainsandtowns","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmmushfiq%2Ftrainsandtowns/lists"}