Last active
January 27, 2022 02:33
-
-
Save theptrk/2d9d3378e7726529aeabf3b1f5b43a76 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Q: what are all the shortest paths from a single node to all other nodes? | |
""" | |
Example: All shortest paths from id:0 to all other nodes | |
{0: [[]], | |
1: [[1]], | |
2: [[2]], | |
3: [[1, 3], [2, 3]], | |
4: [[1, 3, 4], [2, 3, 4]], | |
5: [[1, 3, 4, 5], [2, 3, 4, 5]], | |
6: [[1, 3, 4, 5, 6], [2, 3, 4, 5, 6]], | |
7: [[1, 3, 4, 5, 7], [2, 3, 4, 5, 7]], | |
8: [[1, 3, 4, 5, 6, 8], | |
[2, 3, 4, 5, 6, 8], | |
[1, 3, 4, 5, 7, 8], | |
[2, 3, 4, 5, 7, 8]], | |
9: [[1, 3, 4, 5, 6, 8, 9], | |
[2, 3, 4, 5, 6, 8, 9], | |
[1, 3, 4, 5, 7, 8, 9], | |
[2, 3, 4, 5, 7, 8, 9]]} | |
""" | |
users = [ | |
{"id": 0, "name": "Hero"}, | |
{"id": 1, "name": "Dunn"}, | |
{"id": 2, "name": "Sue"}, | |
{"id": 3, "name": "Chi"}, | |
{"id": 4, "name": "Thor"}, | |
{"id": 5, "name": "Clive"}, | |
{"id": 6, "name": "Hicks"}, | |
{"id": 7, "name": "Devin"}, | |
{"id": 8, "name": "Kate"}, | |
{"id": 9, "name": "Klein"}, | |
] | |
friendships = [ | |
(0,1), | |
(0,2), | |
(1,2), | |
(1,3), | |
(2,3), | |
(3,4), | |
(4,5), | |
(5,6), | |
(5,7), | |
(6,8), | |
(7,8), | |
(8,9), | |
] | |
for user in users: | |
user["friends"] = [] | |
for i,j in friendships: | |
users[i]["friends"].append(users[j]) | |
users[j]["friends"].append(users[i]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is the network diagram by ids